http://hg.openjdk.java.net/jdk9/jdk9/jdk/file/efbc2dabd84c/src/share/classes/sun/launcher/LauncherHelper.java
399 static String getMainClassFromJar(String jarname) {
400 String mainValue = null;
401 try (JarFile jarFile = new JarFile(jarname)) {
402 Manifest manifest = jarFile.getManifest();
403 if (manifest == null) {
404 abort(null, "java.launcher.jar.error2", jarname);
405 }
406 Attributes mainAttrs = manifest.getMainAttributes();
407 if (mainAttrs == null) {
408 abort(null, "java.launcher.jar.error3", jarname);
409 }
410 mainValue = mainAttrs.getValue(MAIN_CLASS);
411 if (mainValue == null) {
412 abort(null, "java.launcher.jar.error3", jarname);
413 }
414
415 /*
416 * Hand off to FXHelper if it detects a JavaFX application
417 * This must be done after ensuring a Main-Class entry
418 * exists to enforce compliance with the jar specification
419 */
420 if (mainAttrs.containsKey(
421 new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) {
422 return FXHelper.class.getName();
423 }
424
425 return mainValue.trim();
426 } catch (IOException ioe) {
427 abort(ioe, "java.launcher.jar.error1", jarname);
428 }
429 return null;
430 }
Note that FXHelper class is loaded because the static field FXHelper.JAVAFX_APPLICATION_MARKER is referenced. If FX is not used by the app, then the FXHelper class is loaded unnecessarily, thus slowing JVM start-up time and wastes space.
The code should be changed so that the JAVAFX_APPLICATION_MARKER field is moved into the LauncherHelper class. This saves about 4KB of footprint.
399 static String getMainClassFromJar(String jarname) {
400 String mainValue = null;
401 try (JarFile jarFile = new JarFile(jarname)) {
402 Manifest manifest = jarFile.getManifest();
403 if (manifest == null) {
404 abort(null, "java.launcher.jar.error2", jarname);
405 }
406 Attributes mainAttrs = manifest.getMainAttributes();
407 if (mainAttrs == null) {
408 abort(null, "java.launcher.jar.error3", jarname);
409 }
410 mainValue = mainAttrs.getValue(MAIN_CLASS);
411 if (mainValue == null) {
412 abort(null, "java.launcher.jar.error3", jarname);
413 }
414
415 /*
416 * Hand off to FXHelper if it detects a JavaFX application
417 * This must be done after ensuring a Main-Class entry
418 * exists to enforce compliance with the jar specification
419 */
420 if (mainAttrs.containsKey(
421 new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) {
422 return FXHelper.class.getName();
423 }
424
425 return mainValue.trim();
426 } catch (IOException ioe) {
427 abort(ioe, "java.launcher.jar.error1", jarname);
428 }
429 return null;
430 }
Note that FXHelper class is loaded because the static field FXHelper.JAVAFX_APPLICATION_MARKER is referenced. If FX is not used by the app, then the FXHelper class is loaded unnecessarily, thus slowing JVM start-up time and wastes space.
The code should be changed so that the JAVAFX_APPLICATION_MARKER field is moved into the LauncherHelper class. This saves about 4KB of footprint.