< prev index next >

src/share/vm/compiler/abstractCompiler.hpp

Print this page


   1 /*
   2  * Copyright (c) 1999, 2014, 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 
  25 #ifndef SHARE_VM_COMPILER_ABSTRACTCOMPILER_HPP
  26 #define SHARE_VM_COMPILER_ABSTRACTCOMPILER_HPP
  27 
  28 #include "ci/compilerInterface.hpp"
  29 









































  30 class AbstractCompiler : public CHeapObj<mtCompiler> {
  31  private:
  32   volatile int _num_compiler_threads;
  33 
  34  protected:
  35   volatile int _compiler_state;
  36   // Used for tracking global state of compiler runtime initialization
  37   enum { uninitialized, initializing, initialized, failed, shut_down };
  38 
  39   // This method returns true for the first compiler thread that reaches that methods.
  40   // This thread will initialize the compiler runtime.
  41   bool should_perform_init();
  42 
  43   // The (closed set) of concrete compiler classes.
  44   enum Type {
  45     none,
  46     c1,
  47     c2,

  48     shark
  49   };
  50 
  51  private:
  52   Type _type;
  53 




  54  public:
  55   AbstractCompiler(Type type) : _type(type), _compiler_state(uninitialized), _num_compiler_threads(0) {}
  56 
  57   // This function determines the compiler thread that will perform the
  58   // shutdown of the corresponding compiler runtime.
  59   bool should_perform_shutdown();
  60 
  61   // Name of this compiler
  62   virtual const char* name() = 0;
  63 
  64   // Missing feature tests
  65   virtual bool supports_native()                 { return true; }
  66   virtual bool supports_osr   ()                 { return true; }
  67   virtual bool can_compile_method(methodHandle method)  { return true; }
  68 
  69   // Determine if the current compiler provides an intrinsic
  70   // for method 'method'. An intrinsic is available if:
  71   //  - the intrinsic is enabled (by using the appropriate command-line flag) and
  72   //  - the platform on which the VM is running supports the intrinsic
  73   //    (i.e., the platform provides the instructions necessary for the compiler


  98   virtual bool is_intrinsic_available(methodHandle method, methodHandle compilation_context) {
  99     return is_intrinsic_supported(method) &&
 100            !vmIntrinsics::is_disabled_by_flags(method, compilation_context);
 101   }
 102 
 103   // Determines if an intrinsic is supported by the compiler, that is,
 104   // the compiler provides the instructions necessary to generate
 105   // the intrinsic code for method 'method'.
 106   //
 107   // The 'is_intrinsic_supported' method is a white list, that is,
 108   // by default no intrinsics are supported by a compiler except
 109   // the ones listed in the method. Overriding methods should conform
 110   // to this behavior.
 111   virtual bool is_intrinsic_supported(methodHandle method) {
 112     return false;
 113   }
 114 
 115   // Compiler type queries.
 116   bool is_c1()                                   { return _type == c1; }
 117   bool is_c2()                                   { return _type == c2; }

 118   bool is_shark()                                { return _type == shark; }
 119 
 120   // Customization
 121   virtual void initialize () = 0;
 122 
 123   void set_num_compiler_threads(int num) { _num_compiler_threads = num;  }
 124   int num_compiler_threads()             { return _num_compiler_threads; }
 125 
 126   // Get/set state of compiler objects
 127   bool is_initialized()           { return _compiler_state == initialized; }
 128   bool is_failed     ()           { return _compiler_state == failed;}
 129   void set_state     (int state);
 130   void set_shut_down ()           { set_state(shut_down); }
 131   // Compilation entry point for methods
 132   virtual void compile_method(ciEnv* env, ciMethod* target, int entry_bci) {
 133     ShouldNotReachHere();
 134   }
 135 
 136 
 137   // Print compilation timers and statistics
 138   virtual void print_timers() {
 139     ShouldNotReachHere();
 140   }




 141 };
 142 
 143 #endif // SHARE_VM_COMPILER_ABSTRACTCOMPILER_HPP
   1 /*
   2  * Copyright (c) 1999, 2015, 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 
  25 #ifndef SHARE_VM_COMPILER_ABSTRACTCOMPILER_HPP
  26 #define SHARE_VM_COMPILER_ABSTRACTCOMPILER_HPP
  27 
  28 #include "ci/compilerInterface.hpp"
  29 
  30 typedef void (*initializer)(void);
  31 
  32 #if INCLUDE_JVMCI
  33 // Per-compiler statistics
  34 class CompilerStatistics VALUE_OBJ_CLASS_SPEC {
  35   friend class VMStructs;
  36 
  37   class Data VALUE_OBJ_CLASS_SPEC {
  38     friend class VMStructs;
  39   public:
  40     elapsedTimer _time;  // time spent compiling
  41     int _bytes;          // number of bytecodes compiled, including inlined bytecodes
  42     int _count;          // number of compilations
  43     Data() : _bytes(0), _count(0) {}
  44     void update(elapsedTimer time, int bytes) {
  45       _time.add(time);
  46       _bytes += bytes;
  47       _count++;
  48     }
  49     void reset() {
  50       _time.reset();
  51     }
  52   };
  53 
  54  public:
  55   Data _standard;  // stats for non-OSR compilations
  56   Data _osr;       // stats for OSR compilations
  57   int _nmethods_size; //
  58   int _nmethods_code_size;
  59   int bytes_per_second() {
  60     int bytes = _standard._bytes + _osr._bytes;
  61     if (bytes == 0) {
  62       return 0;
  63     }
  64     double seconds = _standard._time.seconds() + _osr._time.seconds();
  65     return seconds == 0.0 ? 0 : (int) (bytes / seconds);
  66   }
  67   CompilerStatistics() : _nmethods_size(0), _nmethods_code_size(0) {}
  68 };
  69 #endif // INCLUDE_JVMCI
  70 
  71 class AbstractCompiler : public CHeapObj<mtCompiler> {
  72  private:
  73   volatile int _num_compiler_threads;
  74 
  75  protected:
  76   volatile int _compiler_state;
  77   // Used for tracking global state of compiler runtime initialization
  78   enum { uninitialized, initializing, initialized, failed, shut_down };
  79 
  80   // This method returns true for the first compiler thread that reaches that methods.
  81   // This thread will initialize the compiler runtime.
  82   bool should_perform_init();
  83 
  84   // The (closed set) of concrete compiler classes.
  85   enum Type {
  86     none,
  87     c1,
  88     c2,
  89     jvmci,
  90     shark
  91   };
  92 
  93  private:
  94   Type _type;
  95 
  96 #if INCLUDE_JVMCI
  97   CompilerStatistics _stats;
  98 #endif
  99 
 100  public:
 101   AbstractCompiler(Type type) : _type(type), _compiler_state(uninitialized), _num_compiler_threads(0) {}
 102 
 103   // This function determines the compiler thread that will perform the
 104   // shutdown of the corresponding compiler runtime.
 105   bool should_perform_shutdown();
 106 
 107   // Name of this compiler
 108   virtual const char* name() = 0;
 109 
 110   // Missing feature tests
 111   virtual bool supports_native()                 { return true; }
 112   virtual bool supports_osr   ()                 { return true; }
 113   virtual bool can_compile_method(methodHandle method)  { return true; }
 114 
 115   // Determine if the current compiler provides an intrinsic
 116   // for method 'method'. An intrinsic is available if:
 117   //  - the intrinsic is enabled (by using the appropriate command-line flag) and
 118   //  - the platform on which the VM is running supports the intrinsic
 119   //    (i.e., the platform provides the instructions necessary for the compiler


 144   virtual bool is_intrinsic_available(methodHandle method, methodHandle compilation_context) {
 145     return is_intrinsic_supported(method) &&
 146            !vmIntrinsics::is_disabled_by_flags(method, compilation_context);
 147   }
 148 
 149   // Determines if an intrinsic is supported by the compiler, that is,
 150   // the compiler provides the instructions necessary to generate
 151   // the intrinsic code for method 'method'.
 152   //
 153   // The 'is_intrinsic_supported' method is a white list, that is,
 154   // by default no intrinsics are supported by a compiler except
 155   // the ones listed in the method. Overriding methods should conform
 156   // to this behavior.
 157   virtual bool is_intrinsic_supported(methodHandle method) {
 158     return false;
 159   }
 160 
 161   // Compiler type queries.
 162   bool is_c1()                                   { return _type == c1; }
 163   bool is_c2()                                   { return _type == c2; }
 164   bool is_jvmci()                                { return _type == jvmci; }
 165   bool is_shark()                                { return _type == shark; }
 166 
 167   // Customization
 168   virtual void initialize () = 0;
 169 
 170   void set_num_compiler_threads(int num) { _num_compiler_threads = num;  }
 171   int num_compiler_threads()             { return _num_compiler_threads; }
 172 
 173   // Get/set state of compiler objects
 174   bool is_initialized()           { return _compiler_state == initialized; }
 175   bool is_failed     ()           { return _compiler_state == failed;}
 176   void set_state     (int state);
 177   void set_shut_down ()           { set_state(shut_down); }
 178   // Compilation entry point for methods
 179   virtual void compile_method(ciEnv* env, ciMethod* target, int entry_bci) {
 180     ShouldNotReachHere();
 181   }
 182 
 183 
 184   // Print compilation timers and statistics
 185   virtual void print_timers() {
 186     ShouldNotReachHere();
 187   }
 188 
 189 #if INCLUDE_JVMCI
 190   CompilerStatistics* stats() { return &_stats; }
 191 #endif
 192 };
 193 
 194 #endif // SHARE_VM_COMPILER_ABSTRACTCOMPILER_HPP
< prev index next >