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