-
JEP
-
Resolution: Unresolved
-
P4
-
None
-
Magnus Ihse Bursie
-
Informational
-
Open
-
JDK
Summary
This informational JEP describes the overall layout and structure of the JDK source code and related files in the JDK repository.
Motivation
Having a clear and communicated structure helps developers understand code relationship and location. It minimizes the risk of "bike shedding", makes the code easier to maintain, and enables engineers to focus on relevant aspects of the functionality instead of superficial code organization.
The structure of the bulk of the JDK source code, residing in src/$MODULE, was
described by JEP 201 (Modular Source Code).
However, adapting the source code structure is an ongoing process, and this
informational JEP can be kept up-to-date as needed.
Description
The top-level directory of the JDK repository contains the following directories:
srctestmakedocbin
The top-level directory also contains a highly restricted set of individual files. These include essential legal documents, contributor information and necessary build system files. Great restriction should be exercised before introducing additional top-level files, and this should be avoided if at all possible.
The src directory
The src directory contains the source code that is used to build the JDK. It
consists of individual directories for the modules that comprise the JDK, and a
separate directory for the Hotspot JVM.
Overview of the src directory structure:
src/hotspot/share/
cpu/$CPU/
os/$OS/
os_cpu/$OS_$CPU/
$MODULE/{share,$OS}/classes/$PACKAGE/
native/include/
common/
lib$LIBRARY/
$EXECUTABLE/
man/
legal/
data/
conf/
lib/
utils/
src/hotspotcontains the Hotspot source code. Hotspot code is written in C++.src/hotspot/sharecontains shared, cross-platform code.src/hotspot/cpu/$CPUcontains code that is dependent on a particular CPU.$CPUdenotes a particular CPU architecture, e.g.aarch64,x64, etc.src/hotspot/os/$OScontains code that is dependent on a particular operating system.$OSdenotes a particular OS or OS family, e.g.linux,windows, etc. Note that due to historical reasons,unixis calledposix, andmacosis calledbsd.src/hotspot/os_cpu/$OS_$CPUcontains code that is dependent on both a particular OS and a particular CPU.
Files in
src/hotspot/cpu/$CPUare normally named ending in_$CPU.{hpp,cpp}. Likewise are files insrc/hotspot/os/$OSandsrc/hotspot/os_cpu/$OS_$CPUnormally named ending in*_$OS.{hpp,cpp}and*_$OS_$CPU.{hpp,cpp}, respectively.The
src/$MODULEset of directories contain source code for the individual JDK modules.$MODULEis the module name (e.g.,java.base).The
sharedirectory contains shared, cross-platform code and related files.The
$OSdirectory contains operating system specific code and related files.$OSdenotes a particular OS or OS family, e.g.unix,windows, etc. Note that due to historical reasons,macosis calledmacosx.src/$MODULE/{share,$OS}/classescontains Java source files and resource files organized into a directory tree reflecting their API$PACKAGEhierarchy.src/$MODULE/{share,$OS}/native/includecontains C or C++ header files intended to be exported for external use (e.g.,jni.h).src/$MODULE/{share,$OS}/native/commoncontains C or C++ source or header files shared between multiple native libraries or executables in this module.src/$MODULE/{share,$OS}/native/lib$LIBRARYcontains C or C++ source files that will be built to a shared library or DLL with the name$LIBRARY. For instance, the files insrc/java.base/share/native/libjavawill be compiled intojava.dll,libjava.soorlibjava.dylib, depending on platform.src/$MODULE/{share,$OS}/native/$EXECUTABLEcontains C or C++ source files that will be built to an executable binary with the name$EXECUTABLEor$EXECUTABLE.exe, depending on platform.The
mandirectory contains man pages in nroff or Markdown format.The
legaldirectory contains legal notices for included 3rd party code, in Markdown format.The
datadirectory contains data files needed to build the module.The
confdirectory contains configuration files meant to be edited by end users.The
libdirectory contains configuration files not meant to be edited by end users.
src/utilscontains stand-alone utilities designed to help JDK developers. Each utility resides in a separate directory withinsrc/utils, but the structure of individual utilities is left unspecified
Additional legacy directories directly under src might be present, but new
such directories should not be added.
The test directory
The test directory contains code for running tests on the JDK, or files that
are needed to support writing or running tests.
Overview of the test directory structure:
test/hotspot/gtest/
jtreg/
jdk/
langtools/
micro/
make/
lib/
lib-test/
test/hotspot/gtestcontains GTest based unit tests for code undersrc/hotspot.test/hotspot/jtregcontains JTReg based tests for code undersrc/hotspot.test/jdkandtest/langtoolscontains JTReg based tests for code undersrc/$MODULE. For historical reasons, tests for some modules are located intest/langtoolsinstead oftest/jdk.test/microcontains microbenchmarks, i.e. tests designed to check performance of a singe, well-defined task.test/makecontains tests that exercise the build system.test/libcontains various code that supports the writing or execution of other tests.test/lib-testcontains tests that checkstest/lib.
The test directory also contains a few other directories to support various
special case testing. Exercise great restriction before adding new directories
directly under test.
The make directory
The make directory contains files used by or related to the JDK build system.
Overview of the make directory structure:
make/conf/
modules/$MODULE/
make/confcontains essential configuration for the JDK build.The
make/modules/$MODULEset of directories contain makefile snippets for individual modules that require special build handling, or need to override default build settings.
Additional files and directories in make are build system implementation
specific and subject to change.
The doc directory
The doc directory contains documentation that can be helpful for JDK
developers.
The criteria for documentation to fit in the doc directory is that:
it is not intended to be shipped with the built JDK,
it is targeting JDK developers as opposed to JDK users, and
the content is tied to a particular release or otherwise related to the current content of the repository.
The documentation in doc is typically provided in both Markdown and HTML
format, which are updated in tandem.
The bin directory
The bin directory contains an assortment of scripts that can assist JDK
developers in various tasks.
No executable permission is set on the files in this directory, nor any other files in the JDK repository.