1 /*
2  * Copyright (c) 2016, 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 
25 #ifndef SHARE_COMPILER_COMPILERDEFINITIONS_HPP
26 #define SHARE_COMPILER_COMPILERDEFINITIONS_HPP
27 
28 #include "memory/allocation.hpp"
29 
30 // The (closed set) of concrete compiler classes.
31 enum CompilerType {
32   compiler_none,
33   compiler_c1,
34   compiler_c2,
35   compiler_jvmci,
36   compiler_number_of_types
37 };
38 
39 extern const char* compilertype2name_tab[compiler_number_of_types];     // Map CompilerType to its name
compilertype2name(CompilerType t)40 inline const char* compilertype2name(CompilerType t) { return (uint)t < compiler_number_of_types ? compilertype2name_tab[t] : NULL; }
41 
42 // Handy constants for deciding which compiler mode to use.
43 enum MethodCompilation {
44   InvocationEntryBci   = -1,     // i.e., not a on-stack replacement compilation
45   BeforeBci            = InvocationEntryBci,
46   AfterBci             = -2,
47   UnwindBci            = -3,
48   AfterExceptionBci    = -4,
49   UnknownBci           = -5,
50   InvalidFrameStateBci = -6
51 };
52 
53 // Enumeration to distinguish tiers of compilation
54 enum CompLevel {
55   CompLevel_any               = -2,
56   CompLevel_all               = -2,
57   CompLevel_aot               = -1,
58   CompLevel_none              = 0,         // Interpreter
59   CompLevel_simple            = 1,         // C1
60   CompLevel_limited_profile   = 2,         // C1, invocation & backedge counters
61   CompLevel_full_profile      = 3,         // C1, invocation & backedge counters + mdo
62   CompLevel_full_optimization = 4          // C2 or JVMCI
63 };
64 
65 #ifdef TIERED
66 class CompilationModeFlag : AllStatic {
67   static bool _quick_only;
68   static bool _high_only;
69   static bool _high_only_quick_internal;
70 
71 public:
72   static bool initialize();
normal()73   static bool normal()                   { return !quick_only() && !high_only() && !high_only_quick_internal(); }
quick_only()74   static bool quick_only()               { return _quick_only;               }
high_only()75   static bool high_only()                { return _high_only;                }
high_only_quick_internal()76   static bool high_only_quick_internal() { return _high_only_quick_internal; }
77 
disable_intermediate()78   static bool disable_intermediate()     { return high_only() || high_only_quick_internal(); }
quick_internal()79   static bool quick_internal()           { return !high_only(); }
80 
set_high_only_quick_internal(bool x)81   static void set_high_only_quick_internal(bool x) { _high_only_quick_internal = x; }
82 };
83 #endif
84 
85 extern CompLevel CompLevel_highest_tier;
86 
87 enum CompMode {
88   CompMode_none = 0,
89   CompMode_client = 1,
90   CompMode_server = 2
91 };
92 
93 extern CompMode Compilation_mode;
94 
is_server_compilation_mode_vm()95 inline bool is_server_compilation_mode_vm() {
96   return Compilation_mode == CompMode_server;
97 }
98 
is_client_compilation_mode_vm()99 inline bool is_client_compilation_mode_vm() {
100   return Compilation_mode == CompMode_client;
101 }
102 
is_c1_compile(int comp_level)103 inline bool is_c1_compile(int comp_level) {
104   return comp_level > CompLevel_none && comp_level < CompLevel_full_optimization;
105 }
106 
is_c2_compile(int comp_level)107 inline bool is_c2_compile(int comp_level) {
108   return comp_level == CompLevel_full_optimization;
109 }
110 
is_highest_tier_compile(int comp_level)111 inline bool is_highest_tier_compile(int comp_level) {
112   return comp_level == CompLevel_highest_tier;
113 }
114 
is_compile(int comp_level)115 inline bool is_compile(int comp_level) {
116   return is_c1_compile(comp_level) || is_c2_compile(comp_level);
117 }
118 
119 // States of Restricted Transactional Memory usage.
120 enum RTMState {
121   NoRTM      = 0x2, // Don't use RTM
122   UseRTM     = 0x1, // Use RTM
123   ProfileRTM = 0x0  // Use RTM with abort ratio calculation
124 };
125 
126 #ifndef INCLUDE_RTM_OPT
127 #define INCLUDE_RTM_OPT 0
128 #endif
129 #if INCLUDE_RTM_OPT
130 #define RTM_OPT_ONLY(code) code
131 #else
132 #define RTM_OPT_ONLY(code)
133 #endif
134 
135 class CompilerConfig : public AllStatic {
136 public:
137   // Scale compile thresholds
138   // Returns threshold scaled with CompileThresholdScaling
139   static intx scaled_compile_threshold(intx threshold, double scale);
140   static intx scaled_compile_threshold(intx threshold);
141 
142   // Returns freq_log scaled with CompileThresholdScaling
143   static intx scaled_freq_log(intx freq_log, double scale);
144   static intx scaled_freq_log(intx freq_log);
145 
146   static bool check_args_consistency(bool status);
147 
148   static void ergo_initialize();
149 
150 private:
151   TIERED_ONLY(static void set_tiered_flags();)
152 };
153 
154 #endif // SHARE_COMPILER_COMPILERDEFINITIONS_HPP
155