001 /*
002 * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.lang;
027
028 /**
029 * The {@code Compiler} class is provided to support Java-to-native-code
030 * compilers and related services. By design, the {@code Compiler} class does
031 * nothing; it serves as a placeholder for a JIT compiler implementation.
032 *
033 * <p> When the Java Virtual Machine first starts, it determines if the system
034 * property {@code java.compiler} exists. (System properties are accessible
035 * through {@link System#getProperty(String)} and {@link
036 * System#getProperty(String, String)}. If so, it is assumed to be the name of
037 * a library (with a platform-dependent exact location and type); {@link
038 * System#loadLibrary} is called to load that library. If this loading
039 * succeeds, the function named {@code java_lang_Compiler_start()} in that
040 * library is called.
041 *
042 * <p> If no compiler is available, these methods do nothing.
043 *
044 * @author Frank Yellin
045 * @version 1.29, 05/05/07
046 * @since JDK1.0
047 */
048 public final class Compiler {
049 private Compiler() {
050 } // don't make instances
051
052 private static native void initialize();
053
054 private static native void registerNatives();
055
056 static {
057 registerNatives();
058 java.security.AccessController
059 .doPrivileged(new java.security.PrivilegedAction() {
060 public Object run() {
061 boolean loaded = false;
062 String jit = System
063 .getProperty("java.compiler");
064 if ((jit != null) && (!jit.equals("NONE"))
065 && (!jit.equals(""))) {
066 try {
067 System.loadLibrary(jit);
068 initialize();
069 loaded = true;
070 } catch (UnsatisfiedLinkError e) {
071 System.err
072 .println("Warning: JIT compiler \""
073 + jit
074 + "\" not found. Will use interpreter.");
075 }
076 }
077 String info = System
078 .getProperty("java.vm.info");
079 if (loaded) {
080 System.setProperty("java.vm.info", info
081 + ", " + jit);
082 } else {
083 System.setProperty("java.vm.info", info
084 + ", nojit");
085 }
086 return null;
087 }
088 });
089 }
090
091 /**
092 * Compiles the specified class.
093 *
094 * @param clazz
095 * A class
096 *
097 * @return {@code true} if the compilation succeeded; {@code false} if the
098 * compilation failed or no compiler is available
099 *
100 * @throws NullPointerException
101 * If {@code clazz} is {@code null}
102 */
103 public static native boolean compileClass(Class<?> clazz);
104
105 /**
106 * Compiles all classes whose name matches the specified string.
107 *
108 * @param string
109 * The name of the classes to compile
110 *
111 * @return {@code true} if the compilation succeeded; {@code false} if the
112 * compilation failed or no compiler is available
113 *
114 * @throws NullPointerException
115 * If {@code string} is {@code null}
116 */
117 public static native boolean compileClasses(String string);
118
119 /**
120 * Examines the argument type and its fields and perform some documented
121 * operation. No specific operations are required.
122 *
123 * @param any
124 * An argument
125 *
126 * @return A compiler-specific value, or {@code null} if no compiler is
127 * available
128 *
129 * @throws NullPointerException
130 * If {@code any} is {@code null}
131 */
132 public static native Object command(Object any);
133
134 /**
135 * Cause the Compiler to resume operation.
136 */
137 public static native void enable();
138
139 /**
140 * Cause the Compiler to cease operation.
141 */
142 public static native void disable();
143 }
|