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