Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/lang/Compiler.java
38829 views
/*1* Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.lang;2627/**28* The {@code Compiler} class is provided to support Java-to-native-code29* compilers and related services. By design, the {@code Compiler} class does30* nothing; it serves as a placeholder for a JIT compiler implementation.31*32* <p> When the Java Virtual Machine first starts, it determines if the system33* property {@code java.compiler} exists. (System properties are accessible34* through {@link System#getProperty(String)} and {@link35* System#getProperty(String, String)}. If so, it is assumed to be the name of36* a library (with a platform-dependent exact location and type); {@link37* System#loadLibrary} is called to load that library. If this loading38* succeeds, the function named {@code java_lang_Compiler_start()} in that39* library is called.40*41* <p> If no compiler is available, these methods do nothing.42*43* @author Frank Yellin44* @since JDK1.045*/46public final class Compiler {47private Compiler() {} // don't make instances4849private static native void initialize();5051private static native void registerNatives();5253static {54registerNatives();55java.security.AccessController.doPrivileged(56new java.security.PrivilegedAction<Void>() {57public Void run() {58boolean loaded = false;59String jit = System.getProperty("java.compiler");60if ((jit != null) && (!jit.equals("NONE")) &&61(!jit.equals("")))62{63try {64System.loadLibrary(jit);65initialize();66loaded = true;67} catch (UnsatisfiedLinkError e) {68System.err.println("Warning: JIT compiler \"" +69jit + "\" not found. Will use interpreter.");70}71}72String info = System.getProperty("java.vm.info");73if (loaded) {74System.setProperty("java.vm.info", info + ", " + jit);75} else {76System.setProperty("java.vm.info", info + ", nojit");77}78return null;79}80});81}8283/**84* Compiles the specified class.85*86* @param clazz87* A class88*89* @return {@code true} if the compilation succeeded; {@code false} if the90* compilation failed or no compiler is available91*92* @throws NullPointerException93* If {@code clazz} is {@code null}94*/95public static native boolean compileClass(Class<?> clazz);9697/**98* Compiles all classes whose name matches the specified string.99*100* @param string101* The name of the classes to compile102*103* @return {@code true} if the compilation succeeded; {@code false} if the104* compilation failed or no compiler is available105*106* @throws NullPointerException107* If {@code string} is {@code null}108*/109public static native boolean compileClasses(String string);110111/**112* Examines the argument type and its fields and perform some documented113* operation. No specific operations are required.114*115* @param any116* An argument117*118* @return A compiler-specific value, or {@code null} if no compiler is119* available120*121* @throws NullPointerException122* If {@code any} is {@code null}123*/124public static native Object command(Object any);125126/**127* Cause the Compiler to resume operation.128*/129public static native void enable();130131/**132* Cause the Compiler to cease operation.133*/134public static native void disable();135}136137138