1 /* 2 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 #ifndef SHARE_JVMCI_JVMCICOMPILER_HPP 25 #define SHARE_JVMCI_JVMCICOMPILER_HPP 26 27 #include "compiler/abstractCompiler.hpp" 28 29 class JVMCICompiler : public AbstractCompiler { 30 private: 31 bool _bootstrapping; 32 33 /** 34 * True if we have seen a bootstrap compilation request. 35 */ 36 volatile bool _bootstrap_compilation_request_handled; 37 38 /** 39 * Number of methods successfully compiled by a call to 40 * JVMCICompiler::compile_method(). 41 */ 42 volatile int _methods_compiled; 43 44 static JVMCICompiler* _instance; 45 46 static elapsedTimer _codeInstallTimer; 47 48 /** 49 * Exits the VM due to an unexpected exception. 50 */ 51 static void exit_on_pending_exception(oop exception, const char* message); 52 53 public: 54 JVMCICompiler(); 55 56 static JVMCICompiler* instance(bool require_non_null, TRAPS) { 57 if (!EnableJVMCI) { 58 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVMCI is not enabled") 59 } 60 if (_instance == NULL && require_non_null) { 61 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "The JVMCI compiler instance has not been created"); 62 } 63 return _instance; 64 } 65 66 virtual const char* name() { return UseJVMCINativeLibrary ? "JVMCI-native" : "JVMCI"; } 67 68 virtual bool supports_native() { return true; } 69 virtual bool supports_osr () { return true; } 70 71 bool is_jvmci() { return true; } 72 bool is_c1 () { return false; } 73 bool is_c2 () { return false; } 74 75 bool needs_stubs () { return false; } 76 77 // Initialization 78 virtual void initialize(); 79 80 /** 81 * Initialize the compile queue with the methods in java.lang.Object and 82 * then wait until the queue is empty. 83 */ 84 void bootstrap(TRAPS); 85 86 bool is_bootstrapping() const { return _bootstrapping; } 87 88 void set_bootstrap_compilation_request_handled() { 89 _instance->_bootstrap_compilation_request_handled = true; 90 } 91 92 // Compilation entry point for methods 93 virtual void compile_method(ciEnv* env, ciMethod* target, int entry_bci, DirectiveSet* directive); 94 95 // Print compilation timers and statistics 96 virtual void print_timers(); 97 98 /** 99 * Gets the number of methods that have been successfully compiled by 100 * a call to JVMCICompiler::compile_method(). 101 */ 102 int methods_compiled() { return _methods_compiled; } 103 104 void inc_methods_compiled() { 105 Atomic::inc(&_methods_compiled); 106 } 107 108 // Print compilation timers and statistics 109 static void print_compilation_timers(); 110 111 static elapsedTimer* codeInstallTimer() { return &_codeInstallTimer; } 112 }; 113 114 #endif // SHARE_JVMCI_JVMCICOMPILER_HPP