1 /* 2 * Copyright (c) 1998, 2017, 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_COMPILERDIRECTIVES_HPP 26 #define SHARE_VM_COMPILER_COMPILERDIRECTIVES_HPP 27 28 #include "ci/ciMetadata.hpp" 29 #include "ci/ciMethod.hpp" 30 #include "ci/ciUtilities.hpp" 31 #include "compiler/methodMatcher.hpp" 32 #include "compiler/compilerOracle.hpp" 33 #include "utilities/exceptions.hpp" 34 35 // Directives flag name, type, default value, compile command name 36 #define compilerdirectives_common_flags(cflags) \ 37 cflags(Enable, bool, false, X) \ 38 cflags(Exclude, bool, false, X) \ 39 cflags(BreakAtExecute, bool, false, X) \ 40 cflags(BreakAtCompile, bool, false, X) \ 41 cflags(Log, bool, LogCompilation, X) \ 42 cflags(PrintAssembly, bool, PrintAssembly, PrintAssembly) \ 43 cflags(PrintInlining, bool, PrintInlining, PrintInlining) \ 44 cflags(PrintNMethods, bool, PrintNMethods, PrintNMethods) \ 45 cflags(BackgroundCompilation, bool, BackgroundCompilation, BackgroundCompilation) \ 46 cflags(ReplayInline, bool, false, ReplayInline) \ 47 cflags(DumpReplay, bool, false, DumpReplay) \ 48 cflags(DumpInline, bool, false, DumpInline) \ 49 cflags(CompilerDirectivesIgnoreCompileCommands, bool, CompilerDirectivesIgnoreCompileCommands, X) \ 50 cflags(DisableIntrinsic, ccstrlist, DisableIntrinsic, DisableIntrinsic) 51 52 #ifdef COMPILER1 53 #define compilerdirectives_c1_flags(cflags) 54 #else 55 #define compilerdirectives_c1_flags(cflags) 56 #endif 57 58 #ifdef COMPILER2 59 #define compilerdirectives_c2_flags(cflags) \ 60 cflags(BlockLayoutByFrequency, bool, BlockLayoutByFrequency, BlockLayoutByFrequency) \ 61 cflags(PrintOptoAssembly, bool, PrintOptoAssembly, PrintOptoAssembly) \ 62 cflags(PrintIntrinsics, bool, PrintIntrinsics, PrintIntrinsics) \ 63 NOT_PRODUCT(cflags(TraceOptoPipelining, bool, TraceOptoPipelining, TraceOptoPipelining)) \ 64 NOT_PRODUCT(cflags(TraceOptoOutput, bool, TraceOptoOutput, TraceOptoOutput)) \ 65 cflags(TraceSpilling, bool, TraceSpilling, TraceSpilling) \ 66 cflags(Vectorize, bool, false, Vectorize) \ 67 cflags(VectorizeDebug, uintx, 0, VectorizeDebug) \ 68 cflags(CloneMapDebug, bool, false, CloneMapDebug) \ 69 cflags(IGVPrintLevel, intx, PrintIdealGraphLevel, IGVPrintLevel) \ 70 cflags(MaxNodeLimit, intx, MaxNodeLimit, MaxNodeLimit) \ 71 /* ZGC */ \ 72 cflags(OptimizeLoadBarriers, bool, OptimizeLoadBarriers, OptimizeLoadBarriers) \ 73 cflags(UseBasicLoadBarrier, bool, UseBasicLoadBarrier, UseBasicLoadBarrier) \ 74 /* ZGC temporary flags */ \ 75 cflags(UseCASLoadBarrier, bool, UseCASLoadBarrier, UseCASLoadBarrier) \ 76 cflags(UseWeakCASLoadBarrier, bool, UseWeakCASLoadBarrier, UseWeakCASLoadBarrier) \ 77 cflags(UseCMPXLoadBarrier, bool, UseCMPXLoadBarrier, UseCMPXLoadBarrier) \ 78 cflags(UseSwapLoadBarrier, bool, UseSwapLoadBarrier, UseSwapLoadBarrier) 79 #else 80 #define compilerdirectives_c2_flags(cflags) 81 #endif 82 83 class CompilerDirectives; 84 class DirectiveSet; 85 86 class DirectivesStack : AllStatic { 87 private: 88 static CompilerDirectives* _top; 89 static CompilerDirectives* _bottom; 90 static int _depth; 91 92 static void pop_inner(); // no lock version of pop 93 public: 94 static void init(); 95 static DirectiveSet* getMatchingDirective(const methodHandle& mh, AbstractCompiler* comp); 96 static DirectiveSet* getDefaultDirective(AbstractCompiler* comp); 97 static void push(CompilerDirectives* directive); 98 static void pop(int count); 99 static bool check_capacity(int request_size, outputStream* st); 100 static void clear(); 101 static void print(outputStream* st); 102 static void release(DirectiveSet* set); 103 static void release(CompilerDirectives* dir); 104 }; 105 106 class DirectiveSet : public CHeapObj<mtCompiler> { 107 private: 108 InlineMatcher* _inlinematchers; 109 CompilerDirectives* _directive; 110 111 public: 112 DirectiveSet(CompilerDirectives* directive); 113 ~DirectiveSet(); 114 CompilerDirectives* directive(); 115 bool parse_and_add_inline(char* str, const char*& error_msg); 116 void append_inline(InlineMatcher* m); 117 bool should_inline(ciMethod* inlinee); 118 bool should_not_inline(ciMethod* inlinee); 119 void print_inline(outputStream* st); 120 DirectiveSet* compilecommand_compatibility_init(const methodHandle& method); 121 bool is_exclusive_copy() { return _directive == NULL; } 122 bool matches_inline(const methodHandle& method, int inline_action); 123 static DirectiveSet* clone(DirectiveSet const* src); 124 bool is_intrinsic_disabled(const methodHandle& method); 125 static ccstrlist canonicalize_disableintrinsic(ccstrlist option_value); 126 void finalize(outputStream* st); 127 128 typedef enum { 129 #define enum_of_flags(name, type, dvalue, cc_flag) name##Index, 130 compilerdirectives_common_flags(enum_of_flags) 131 compilerdirectives_c2_flags(enum_of_flags) 132 compilerdirectives_c1_flags(enum_of_flags) 133 number_of_flags 134 } flags; 135 136 bool _modified[number_of_flags]; // Records what options where set by a directive 137 138 #define flag_store_definition(name, type, dvalue, cc_flag) type name##Option; 139 compilerdirectives_common_flags(flag_store_definition) 140 compilerdirectives_c2_flags(flag_store_definition) 141 compilerdirectives_c1_flags(flag_store_definition) 142 143 // Casting to get the same function signature for all setters. Used from parser. 144 #define set_function_definition(name, type, dvalue, cc_flag) void set_##name(void* value) { type val = *(type*)value; name##Option = val; _modified[name##Index] = true; } 145 compilerdirectives_common_flags(set_function_definition) 146 compilerdirectives_c2_flags(set_function_definition) 147 compilerdirectives_c1_flags(set_function_definition) 148 149 void print_intx(outputStream* st, ccstr n, intx v, bool mod) { if (mod) { st->print("%s:" INTX_FORMAT " ", n, v); } } 150 void print_uintx(outputStream* st, ccstr n, intx v, bool mod) { if (mod) { st->print("%s:" UINTX_FORMAT " ", n, v); } } 151 void print_bool(outputStream* st, ccstr n, bool v, bool mod) { if (mod) { st->print("%s:%s ", n, v ? "true" : "false"); } } 152 void print_double(outputStream* st, ccstr n, double v, bool mod) { if (mod) { st->print("%s:%f ", n, v); } } 153 void print_ccstr(outputStream* st, ccstr n, ccstr v, bool mod) { if (mod) { st->print("%s:%s ", n, v); } } 154 void print_ccstrlist(outputStream* st, ccstr n, ccstr v, bool mod) { print_ccstr(st, n, v, mod); } 155 156 void print(outputStream* st) { 157 print_inline(st); 158 st->print(" "); 159 #define print_function_definition(name, type, dvalue, cc_flag) print_##type(st, #name, this->name##Option, true); 160 compilerdirectives_common_flags(print_function_definition) 161 compilerdirectives_c2_flags(print_function_definition) 162 compilerdirectives_c1_flags(print_function_definition) 163 st->cr(); 164 } 165 }; 166 167 class CompilerDirectives : public CHeapObj<mtCompiler> { 168 private: 169 CompilerDirectives* _next; 170 BasicMatcher* _match; 171 int _ref_count; 172 173 public: 174 175 CompilerDirectives(); 176 ~CompilerDirectives(); 177 178 CompilerDirectives* next(); 179 void set_next(CompilerDirectives* next) {_next = next; } 180 181 bool match(const methodHandle& method); 182 BasicMatcher* match() { return _match; } 183 bool add_match(char* str, const char*& error_msg); 184 DirectiveSet* get_for(AbstractCompiler *comp); 185 void print(outputStream* st); 186 bool is_default_directive() { return _next == NULL; } 187 void finalize(outputStream* st); 188 189 void inc_refcount(); 190 void dec_refcount(); 191 int refcount(); 192 193 DirectiveSet* _c1_store; 194 DirectiveSet* _c2_store; 195 }; 196 197 #endif // SHARE_VM_COMPILER_COMPILERDIRECTIVES_HPP