1. /*
  2. * @(#)Compiler.java 1.20 04/05/05
  3. *
  4. * Copyright 2004 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.20, 05/05/04
  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. java.security.AccessController.doPrivileged
  40. (new java.security.PrivilegedAction() {
  41. public Object run() {
  42. boolean loaded = false;
  43. String jit = System.getProperty("java.compiler");
  44. if ((jit != null) && (!jit.equals("NONE")) &&
  45. (!jit.equals("")))
  46. {
  47. try {
  48. System.loadLibrary(jit);
  49. initialize();
  50. loaded = true;
  51. } catch (UnsatisfiedLinkError e) {
  52. System.err.println("Warning: JIT compiler \"" +
  53. jit + "\" not found. Will use interpreter.");
  54. }
  55. }
  56. String info = System.getProperty("java.vm.info");
  57. if (loaded) {
  58. System.setProperty("java.vm.info", info + ", " + jit);
  59. } else {
  60. System.setProperty("java.vm.info", info + ", nojit");
  61. }
  62. return null;
  63. }
  64. });
  65. }
  66. /**
  67. * Compiles the specified class.
  68. *
  69. * @param clazz a class.
  70. * @return <code>true</code> if the compilation succeeded;
  71. * <code>false</code> if the compilation failed or no compiler
  72. * is available.
  73. * @exception NullPointerException if <code>clazz</code> is
  74. * <code>null</code>.
  75. */
  76. public static native boolean compileClass(Class<?> clazz);
  77. /**
  78. * Compiles all classes whose name matches the specified string.
  79. *
  80. * @param string the name of the classes to compile.
  81. * @return <code>true</code> if the compilation succeeded;
  82. * <code>false</code> if the compilation failed or no compiler
  83. * is available.
  84. * @exception NullPointerException if <code>string</code> is
  85. * <code>null</code>.
  86. */
  87. public static native boolean compileClasses(String string);
  88. /**
  89. * Examines the argument type and its fields and perform some documented
  90. * operation. No specific operations are required.
  91. *
  92. * @param any an argument.
  93. * @return a compiler-specific value, or <code>null</code> if no compiler
  94. * is available.
  95. * @exception NullPointerException if <code>any</code> is
  96. * <code>null</code>.
  97. */
  98. public static native Object command(Object any);
  99. /**
  100. * Cause the Compiler to resume operation.
  101. */
  102. public static native void enable();
  103. /**
  104. * Cause the Compiler to cease operation.
  105. */
  106. public static native void disable();
  107. }