Path: blob/master/src/hotspot/share/compiler/abstractCompiler.hpp
40930 views
/*1* Copyright (c) 1999, 2019, 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_COMPILER_ABSTRACTCOMPILER_HPP25#define SHARE_COMPILER_ABSTRACTCOMPILER_HPP2627#include "ci/compilerInterface.hpp"28#include "compiler/compilerDefinitions.hpp"29#include "compiler/compilerDirectives.hpp"3031typedef void (*initializer)(void);3233// Per-compiler statistics34class CompilerStatistics {35friend class VMStructs;3637class Data {38friend class VMStructs;39public:40elapsedTimer _time; // time spent compiling41int _bytes; // number of bytecodes compiled, including inlined bytecodes42int _count; // number of compilations43Data() : _bytes(0), _count(0) {}44void update(elapsedTimer time, int bytes) {45_time.add(time);46_bytes += bytes;47_count++;48}49void reset() {50_time.reset();51}52};5354public:55Data _standard; // stats for non-OSR compilations56Data _osr; // stats for OSR compilations57int _nmethods_size; //58int _nmethods_code_size;5960double total_time() { return _standard._time.seconds() + _osr._time.seconds(); }6162double bytes_per_second() {63int bytes = _standard._bytes + _osr._bytes;64if (bytes == 0) {65return 0.0;66}67double seconds = total_time();68return seconds == 0.0 ? 0.0 : (bytes / seconds);69}7071CompilerStatistics() : _nmethods_size(0), _nmethods_code_size(0) {}72};7374class AbstractCompiler : public CHeapObj<mtCompiler> {75private:76volatile int _num_compiler_threads;7778protected:79volatile int _compiler_state;80// Used for tracking global state of compiler runtime initialization81enum { uninitialized, initializing, initialized, failed, shut_down };8283// This method returns true for the first compiler thread that reaches that methods.84// This thread will initialize the compiler runtime.85bool should_perform_init();8687private:88const CompilerType _type;8990CompilerStatistics _stats;9192public:93AbstractCompiler(CompilerType type) : _num_compiler_threads(0), _compiler_state(uninitialized), _type(type) {}9495// This function determines the compiler thread that will perform the96// shutdown of the corresponding compiler runtime.97bool should_perform_shutdown();9899// Name of this compiler100virtual const char* name() = 0;101102// Determine if the current compiler provides an intrinsic103// for method 'method'. An intrinsic is available if:104// - the intrinsic is enabled (by using the appropriate command-line flag,105// the command-line compile ommand, or a compiler directive)106// - the platform on which the VM is running supports the intrinsic107// (i.e., the platform provides the instructions necessary for the compiler108// to generate the intrinsic code).109//110// The directive provides the compilation context and includes pre-evaluated values111// dependent on VM flags, compile commands, and compiler directives.112//113// Usually, the compilation context is the caller of the method 'method'.114// The only case when for a non-recursive method 'method' the compilation context115// is not the caller of the 'method' (but it is the method itself) is116// java.lang.ref.Referene::get.117// For java.lang.ref.Reference::get, the intrinsic version is used118// instead of the compiled version so that the value in the referent119// field can be registered by the G1 pre-barrier code. The intrinsified120// version of Reference::get also adds a memory barrier to prevent121// commoning reads from the referent field across safepoint since GC122// can change the referent field's value. See Compile::Compile()123// in src/share/vm/opto/compile.cpp or124// GraphBuilder::GraphBuilder() in src/share/vm/c1/c1_GraphBuilder.cpp125// for more details.126127virtual bool is_intrinsic_available(const methodHandle& method, DirectiveSet* directive) {128return is_intrinsic_supported(method) &&129!directive->is_intrinsic_disabled(method) &&130!vmIntrinsics::is_disabled_by_flags(method);131}132133// Determines if an intrinsic is supported by the compiler, that is,134// the compiler provides the instructions necessary to generate135// the intrinsic code for method 'method'.136//137// The 'is_intrinsic_supported' method is an allow-list, that is,138// by default no intrinsics are supported by a compiler except139// the ones listed in the method. Overriding methods should conform140// to this behavior.141virtual bool is_intrinsic_supported(const methodHandle& method) {142return false;143}144145// Compiler type queries.146bool is_c1() const { return _type == compiler_c1; }147bool is_c2() const { return _type == compiler_c2; }148bool is_jvmci() const { return _type == compiler_jvmci; }149CompilerType type() const { return _type; }150151// Customization152virtual void initialize () = 0;153154void set_num_compiler_threads(int num) { _num_compiler_threads = num; }155int num_compiler_threads() { return _num_compiler_threads; }156157// Get/set state of compiler objects158bool is_initialized() { return _compiler_state == initialized; }159bool is_failed () { return _compiler_state == failed;}160void set_state (int state);161void set_shut_down () { set_state(shut_down); }162// Compilation entry point for methods163virtual void compile_method(ciEnv* env, ciMethod* target, int entry_bci, bool install_code, DirectiveSet* directive) {164ShouldNotReachHere();165}166167// Print compilation timers and statistics168virtual void print_timers() {169ShouldNotReachHere();170}171172CompilerStatistics* stats() { return &_stats; }173};174175#endif // SHARE_COMPILER_ABSTRACTCOMPILER_HPP176177178