1 /* 2 * Copyright (c) 1998, 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_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 "oops/oop.inline.hpp" 34 #include "utilities/exceptions.hpp" 35 36 // Directives flag name, type, default value, compile command name 37 #define compilerdirectives_common_flags(cflags) \ 38 cflags(Enabled, bool, true, X) \ 39 cflags(BreakAtExecute, bool, false, X) \ 40 cflags(BreakAtCompile, bool, false, X) \ 41 cflags(Log, bool, false, X) \ 42 cflags(PrintAssembly, bool, PrintAssembly, X) \ 43 cflags(PrintInlining, bool, PrintInlining, PrintInlining) \ 44 cflags(PrintNMethods, bool, PrintNMethods, PrintNMethods) \ 45 cflags(ReplayInline, bool, false, ReplayInline) \ 46 cflags(DumpReplay, bool, false, DumpReplay) \ 47 cflags(DumpInline, bool, false, DumpInline) \ 48 cflags(CompileCommandCompatibility, bool, false, CompileCommandCompatibility) 49 50 #ifdef COMPILER1 51 #define compilerdirectives_c1_flags(cflags) 52 #else 53 #define compilerdirectives_c1_flags(cflags) 54 #endif 55 56 #ifdef COMPILER2 57 #define compilerdirectives_c2_flags(cflags) \ 58 cflags(BlockLayoutByFrequency, bool, BlockLayoutByFrequency, BlockLayoutByFrequency) \ 59 cflags(PrintOptoAssembly, bool, PrintOptoAssembly, PrintOptoAssembly) \ 60 cflags(PrintIntrinsics, bool, PrintIntrinsics, PrintIntrinsics) \ 61 cflags(TraceOptoPipelining, bool, false, TraceOptoPipelining) \ 62 cflags(TraceOptoOutput, bool, false, TraceOptoOutput) \ 63 cflags(TraceSpilling, bool, TraceSpilling, TraceSpilling) \ 64 cflags(Vectorize, bool, false, Vectorize) \ 65 cflags(VectorizeDebug, bool, false, VectorizeDebug) \ 66 cflags(CloneMapDebug, bool, false, CloneMapDebug) \ 67 cflags(IGVPrintLevel, intx, PrintIdealGraphLevel, IGVPrintLevel) \ 68 cflags(MaxNodeLimit, intx, MaxNodeLimit, MaxNodeLimit) \ 69 cflags(DisableIntrinsics, ccstr, DisableIntrinsic, DisableIntrinsics) 70 #else 71 #define compilerdirectives_c2_flags(cflags) 72 #endif 73 74 class CompilerDirectives; 75 76 class DirectiveSet : public CHeapObj<mtCompiler> { 77 private: 78 InlineMatcher* _inlinematchers; 79 CompilerDirectives* _directive; 80 81 public: 82 DirectiveSet(CompilerDirectives* directive); 83 ~DirectiveSet(); 84 CompilerDirectives* directive(); 85 bool parse_and_add_inline(char* str, const char*& error_msg); 86 void append_inline(InlineMatcher* m); 87 bool should_inline(ciMethod* inlinee); 88 bool should_not_inline(ciMethod* inlinee); 89 void print_inline(outputStream* st); 90 DirectiveSet* compilecommand_compatibility_init(methodHandle method); 91 bool is_exclusive_copy() { return _directive == NULL; } 92 bool matches_inline(methodHandle method, int inline_action); 93 bool is_intrinsic_disabled(methodHandle method); 94 DirectiveSet* clone(); 95 96 typedef enum { 97 #define enum_of_flags(name, type, dvalue, cc_flag) name##Index, 98 compilerdirectives_common_flags(enum_of_flags) 99 compilerdirectives_c2_flags(enum_of_flags) 100 compilerdirectives_c1_flags(enum_of_flags) 101 number_of_flags 102 } flags; 103 104 bool _modified[number_of_flags]; 105 106 #define flag_store_definition(name, type, dvalue, cc_flag) type name##Option; 107 compilerdirectives_common_flags(flag_store_definition) 108 compilerdirectives_c2_flags(flag_store_definition) 109 compilerdirectives_c1_flags(flag_store_definition) 110 111 // Casting to get the same function signature for all setters. Used from parser. 112 #define set_function_definition(name, type, dvalue, cc_flag) void set_##name(void* value) { type val = *(type*)value; name##Option = val; _modified[name##Index] = 1; } 113 compilerdirectives_common_flags(set_function_definition) 114 compilerdirectives_c2_flags(set_function_definition) 115 compilerdirectives_c1_flags(set_function_definition) 116 117 void print_intx(outputStream* st, ccstr n, intx v, bool mod) { if (mod) { st->print_cr("%s: " INTX_FORMAT, n, v); } } 118 void print_bool(outputStream* st, ccstr n, bool v, bool mod) { if (mod) { st->print_cr("%s: %s", n, v ? "true" : "false"); } } 119 void print_double(outputStream* st, ccstr n, double v, bool mod) { if (mod) { st->print_cr("%s: %f", n, v); } } 120 void print_ccstr(outputStream* st, ccstr n, ccstr v, bool mod) { if (mod) { st->print_cr("%s: %s", n, v); } } 121 122 void print(outputStream* st) { 123 print_inline(st); 124 #define print_function_definition(name, type, dvalue, cc_flag) print_##type(st, #name, this->name##Option, (bool)_modified[name##Index]); 125 compilerdirectives_common_flags(print_function_definition) 126 compilerdirectives_c2_flags(print_function_definition) 127 compilerdirectives_c1_flags(print_function_definition) 128 } 129 }; 130 131 class CompilerDirectives : public CHeapObj<mtCompiler> { 132 private: 133 CompilerDirectives* _next; 134 BasicMatcher* _match; 135 int _ref_count; 136 137 public: 138 139 CompilerDirectives(); 140 ~CompilerDirectives(); 141 142 CompilerDirectives* next(); 143 void set_next(CompilerDirectives* next) {_next = next; } 144 145 bool match(methodHandle method); 146 bool add_match(char* str, const char*& error_msg); 147 DirectiveSet* get_for(AbstractCompiler *comp); 148 void print(outputStream* st); 149 bool is_default_directive() { return _next == NULL; } 150 151 void inc_refcount(); 152 void dec_refcount(); 153 int refcount(); 154 155 DirectiveSet* _c1_store; 156 DirectiveSet* _c2_store; 157 }; 158 159 class CompilerDirectivesWrapper : StackObj { 160 private: 161 CompilerDirectives* _dir; 162 public: 163 CompilerDirectivesWrapper(CompilerDirectives* dir); 164 ~CompilerDirectivesWrapper(); 165 }; 166 167 class DirectivesSetWrapper : StackObj { 168 private: 169 DirectiveSet* _dirset; 170 public: 171 DirectivesSetWrapper(DirectiveSet* dirset); 172 ~DirectivesSetWrapper(); 173 }; 174 175 #endif // SHARE_VM_COMPILER_COMPILERDIRECTIVES_HPP