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