Tooling support for Compact Profiles

Update: 2013/1/29

This page summarizes the tooling support for the proposed Compact Profiles (JEP-161).

javac

The javac compiler has been updated with the option -profile to specify the profile name when compiling:

javac -profile compact1 Hello.java

Attempting to compile source code that uses Java SE APIs that are not in the given profile will not compile.

The advantage of -profile over specifying -bootclasspath (and a path to a profile image's rt.jar) is that it does not require a profile image to be present on the system at compile-time. This is very useful when cross-compiling.

jar tool

The jar tool has been updated with a -p option that can be used to specify the value of the Profile attribute when creating or updating JAR files. Here is an example that creates an application (executable) JAR file that targets compact1 or higher.

jar cfpe foo.jar compact1 foo.Main foo/*.class ..

Here is an example that adds or updates the Profile attribute in the main manifest of an existing JAR file.

jar ufp bar.jar compact2

jdeps

The JDK includes a command-line tool named jdeps to analyze the class files of applications or libraries to undestand their dependencies.

The tool has an -P that will, in the case of usages of Java SE or JDK specific types, print out the minimum profile that includes this type.

jdeps -P FullThreadDump.jar <unnamed> (FullThreadDump.jar) -> java.io compact1 -> java.lang compact1 -> java.lang.management compact3 -> java.net compact1 -> java.util.concurrent compact1 -> java.util.concurrent.locks compact1 -> javax.management compact3 -> javax.management.remote compact3

jtreg

Profile builds can be tested with jtreg by specifying the -compilejdk and -javacoptions options as in the following example:

jtreg \ -jdk:$IMAGES/j2re-compact3-image \ -compilejdk:$IMAGES/j2sdk-image \ -javacoptions:"-profile compact3" \ ...

The -compilejdk option is required because profile images are runtime images (not JDK images and so don't have javac and the other tools).

The -javacoptions option is used here to specify the -profile to javac. This ensures that tests that are applicable to the profile (they use APIs that are not included in the profile) will not not compile.