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