1. /*
  2. * @(#)Compiler.java 1.16 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.lang;
  8. /**
  9. * The <code>Compiler</code> class is provided to support
  10. * Java-to-native-code compilers and related services. By design, the
  11. * <code>Compiler</code> class does nothing; it serves as a
  12. * placeholder for a JIT compiler implementation.
  13. * <p>
  14. * When the Java Virtual Machine first starts, it determines if the
  15. * system property <code>java.compiler</code> exists. (System
  16. * properties are accessible through <code>getProperty</code> and ,
  17. * a method defined by the <code>System</code> class.) If so, it is
  18. * assumed to be the name of a library (with a platform-dependent
  19. * exact location and type); the <code>loadLibrary</code> method in
  20. * class <code>System</code> is called to load that library. If this
  21. * loading succeeds, the function named
  22. * <code>java_lang_Compiler_start()</code> in that library is called.
  23. * <p>
  24. * If no compiler is available, these methods do nothing.
  25. *
  26. * @author Frank Yellin
  27. * @version 1.12, 06/29/98
  28. * @see java.lang.System#getProperty(java.lang.String)
  29. * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
  30. * @see java.lang.System#loadLibrary(java.lang.String)
  31. * @since JDK1.0
  32. */
  33. public final class Compiler {
  34. private Compiler() {} // don't make instances
  35. private static native void initialize();
  36. private static native void registerNatives();
  37. static {
  38. registerNatives();
  39. String library = null;
  40. boolean loaded = false;
  41. try {
  42. library = System.getProperty("java.compiler");
  43. if ((library != null) &&
  44. (!library.equals("NONE")) &&
  45. (!library.equals(""))) {
  46. System.loadLibrary(library);
  47. initialize();
  48. loaded = true;
  49. }
  50. } catch (UnsatisfiedLinkError e) {
  51. if(!library.equals("javacomp")) {
  52. System.err.println("Warning: JIT compiler \"" + library +
  53. "\" not found. Will use interpreter.");
  54. }
  55. }
  56. String vmInfo = System.getProperty("java.vm.info");
  57. if (loaded) {
  58. System.setProperty("java.vm.info", vmInfo + ", " + library);
  59. } else {
  60. System.setProperty("java.vm.info", vmInfo + ", nojit");
  61. }
  62. }
  63. /**
  64. * Compiles the specified class.
  65. *
  66. * @param clazz a class.
  67. * @return <code>true</code> if the compilation succeeded;
  68. * <code>false</code> if the compilation failed or no compiler
  69. * is available.
  70. */
  71. public static native boolean compileClass(Class clazz);
  72. /**
  73. * Compiles all classes whose name matches the specified string.
  74. *
  75. * @param string the name of the classes to compile.
  76. * @return <code>true</code> if the compilation succeeded;
  77. * <code>false</code> if the compilation failed or no compiler
  78. * is available.
  79. */
  80. public static native boolean compileClasses(String string);
  81. /**
  82. * Examines the argument type and its fields and perform some documented
  83. * operation. No specific operations are required.
  84. *
  85. * @param any an argument.
  86. * @return a compiler-specific value, or <code>null</code> if no compiler
  87. * is available.
  88. */
  89. public static native Object command(Object any);
  90. /**
  91. * Cause the Compiler to resume operation.
  92. */
  93. public static native void enable();
  94. /**
  95. * Cause the Compiler to cease operation.
  96. */
  97. public static native void disable();
  98. }