KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > lang > Compiler


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
8 package java.lang;
9
10 /**
11  * The <code>Compiler</code> class is provided to support
12  * Java-to-native-code compilers and related services. By design, the
13  * <code>Compiler</code> class does nothing; it serves as a
14  * placeholder for a JIT compiler implementation.
15  * <p>
16  * When the Java Virtual Machine first starts, it determines if the
17  * system property <code>java.compiler</code> exists. (System
18  * properties are accessible through <code>getProperty</code> and ,
19  * a method defined by the <code>System</code> class.) If so, it is
20  * assumed to be the name of a library (with a platform-dependent
21  * exact location and type); the <code>loadLibrary</code> method in
22  * class <code>System</code> is called to load that library. If this
23  * loading succeeds, the function named
24  * <code>java_lang_Compiler_start()</code> in that library is called.
25  * <p>
26  * If no compiler is available, these methods do nothing.
27  *
28  * @author Frank Yellin
29  * @version 1.20, 05/05/04
30  * @see java.lang.System#getProperty(java.lang.String)
31  * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
32  * @see java.lang.System#loadLibrary(java.lang.String)
33  * @since JDK1.0
34  */

35 public final class Compiler {
36     private Compiler() {} // don't make instances
37

38     private static native void initialize();
39
40     private static native void registerNatives();
41
42     static {
43         registerNatives();
44     java.security.AccessController.doPrivileged
45         (new java.security.PrivilegedAction JavaDoc() {
46         public Object JavaDoc run() {
47             boolean loaded = false;
48             String JavaDoc jit = System.getProperty("java.compiler");
49             if ((jit != null) && (!jit.equals("NONE")) &&
50             (!jit.equals("")))
51             {
52             try {
53                 System.loadLibrary(jit);
54                 initialize();
55                 loaded = true;
56             } catch (UnsatisfiedLinkError JavaDoc e) {
57                 System.err.println("Warning: JIT compiler \"" +
58                   jit + "\" not found. Will use interpreter.");
59             }
60             }
61             String JavaDoc info = System.getProperty("java.vm.info");
62             if (loaded) {
63             System.setProperty("java.vm.info", info + ", " + jit);
64             } else {
65             System.setProperty("java.vm.info", info + ", nojit");
66             }
67             return null;
68         }
69         });
70     }
71
72     /**
73      * Compiles the specified class.
74      *
75      * @param clazz a class.
76      * @return <code>true</code> if the compilation succeeded;
77      * <code>false</code> if the compilation failed or no compiler
78      * is available.
79      * @exception NullPointerException if <code>clazz</code> is
80      * <code>null</code>.
81      */

82     public static native boolean compileClass(Class JavaDoc<?> clazz);
83
84     /**
85      * Compiles all classes whose name matches the specified string.
86      *
87      * @param string the name of the classes to compile.
88      * @return <code>true</code> if the compilation succeeded;
89      * <code>false</code> if the compilation failed or no compiler
90      * is available.
91      * @exception NullPointerException if <code>string</code> is
92      * <code>null</code>.
93      */

94     public static native boolean compileClasses(String JavaDoc string);
95
96     /**
97      * Examines the argument type and its fields and perform some documented
98      * operation. No specific operations are required.
99      *
100      * @param any an argument.
101      * @return a compiler-specific value, or <code>null</code> if no compiler
102      * is available.
103      * @exception NullPointerException if <code>any</code> is
104      * <code>null</code>.
105      */

106     public static native Object JavaDoc command(Object JavaDoc any);
107
108     /**
109      * Cause the Compiler to resume operation.
110      */

111     public static native void enable();
112
113     /**
114      * Cause the Compiler to cease operation.
115      */

116     public static native void disable();
117 }
118
Popular Tags