Path: blob/master/src/hotspot/share/compiler/compilerDirectives.hpp
40930 views
/*1* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_COMPILER_COMPILERDIRECTIVES_HPP25#define SHARE_COMPILER_COMPILERDIRECTIVES_HPP2627#include "classfile/vmIntrinsics.hpp"28#include "ci/ciMetadata.hpp"29#include "ci/ciMethod.hpp"30#include "compiler/compiler_globals.hpp"31#include "compiler/methodMatcher.hpp"32#include "compiler/compilerOracle.hpp"33#include "utilities/exceptions.hpp"34#include "utilities/tribool.hpp"3536// Directives flag name, type, default value, compile command name37#define compilerdirectives_common_flags(cflags) \38cflags(Enable, bool, false, Unknown) \39cflags(Exclude, bool, false, Unknown) \40cflags(BreakAtExecute, bool, false, BreakAtExecute) \41cflags(BreakAtCompile, bool, false, BreakAtCompile) \42cflags(Log, bool, LogCompilation, Unknown) \43cflags(PrintAssembly, bool, PrintAssembly, PrintAssembly) \44cflags(PrintInlining, bool, PrintInlining, PrintInlining) \45cflags(PrintNMethods, bool, PrintNMethods, PrintNMethods) \46cflags(BackgroundCompilation, bool, BackgroundCompilation, BackgroundCompilation) \47cflags(ReplayInline, bool, false, ReplayInline) \48cflags(DumpReplay, bool, false, DumpReplay) \49cflags(DumpInline, bool, false, DumpInline) \50cflags(CompilerDirectivesIgnoreCompileCommands, bool, CompilerDirectivesIgnoreCompileCommands, Unknown) \51cflags(DisableIntrinsic, ccstrlist, DisableIntrinsic, DisableIntrinsic) \52cflags(ControlIntrinsic, ccstrlist, ControlIntrinsic, ControlIntrinsic) \53cflags(RepeatCompilation, intx, RepeatCompilation, RepeatCompilation)5455#ifdef COMPILER156#define compilerdirectives_c1_flags(cflags)57#else58#define compilerdirectives_c1_flags(cflags)59#endif6061#ifdef COMPILER262#define compilerdirectives_c2_flags(cflags) \63cflags(BlockLayoutByFrequency, bool, BlockLayoutByFrequency, BlockLayoutByFrequency) \64cflags(PrintOptoAssembly, bool, PrintOptoAssembly, PrintOptoAssembly) \65cflags(PrintIntrinsics, bool, PrintIntrinsics, PrintIntrinsics) \66NOT_PRODUCT(cflags(TraceOptoPipelining, bool, TraceOptoPipelining, TraceOptoPipelining)) \67NOT_PRODUCT(cflags(TraceOptoOutput, bool, TraceOptoOutput, TraceOptoOutput)) \68NOT_PRODUCT(cflags(PrintIdeal, bool, PrintIdeal, PrintIdeal)) \69cflags(TraceSpilling, bool, TraceSpilling, TraceSpilling) \70cflags(Vectorize, bool, false, Vectorize) \71cflags(CloneMapDebug, bool, false, CloneMapDebug) \72NOT_PRODUCT(cflags(IGVPrintLevel, intx, PrintIdealGraphLevel, IGVPrintLevel)) \73cflags(VectorizeDebug, uintx, 0, VectorizeDebug) \74cflags(IncrementalInlineForceCleanup, bool, IncrementalInlineForceCleanup, IncrementalInlineForceCleanup) \75cflags(MaxNodeLimit, intx, MaxNodeLimit, MaxNodeLimit)76#else77#define compilerdirectives_c2_flags(cflags)78#endif7980class AbstractCompiler;81class CompilerDirectives;82class DirectiveSet;8384class DirectivesStack : AllStatic {85private:86static CompilerDirectives* _top;87static CompilerDirectives* _bottom;88static int _depth;8990static void pop_inner(); // no lock version of pop91public:92static void init();93static DirectiveSet* getMatchingDirective(const methodHandle& mh, AbstractCompiler* comp);94static DirectiveSet* getDefaultDirective(AbstractCompiler* comp);95static void push(CompilerDirectives* directive);96static void pop(int count);97static bool check_capacity(int request_size, outputStream* st);98static void clear();99static void print(outputStream* st);100static void release(DirectiveSet* set);101static void release(CompilerDirectives* dir);102};103104class DirectiveSet : public CHeapObj<mtCompiler> {105private:106InlineMatcher* _inlinematchers;107CompilerDirectives* _directive;108TriBoolArray<(size_t)vmIntrinsics::number_of_intrinsics(), int> _intrinsic_control_words;109110public:111DirectiveSet(CompilerDirectives* directive);112~DirectiveSet();113void init_control_intrinsic();114CompilerDirectives* directive();115bool parse_and_add_inline(char* str, const char*& error_msg);116void append_inline(InlineMatcher* m);117bool should_inline(ciMethod* inlinee);118bool should_not_inline(ciMethod* inlinee);119void print_inline(outputStream* st);120DirectiveSet* compilecommand_compatibility_init(const methodHandle& method);121bool is_exclusive_copy() { return _directive == NULL; }122bool matches_inline(const methodHandle& method, int inline_action);123static DirectiveSet* clone(DirectiveSet const* src);124bool is_intrinsic_disabled(const methodHandle& method);125static ccstrlist canonicalize_control_intrinsic(ccstrlist option_value);126void finalize(outputStream* st);127128typedef enum {129#define enum_of_flags(name, type, dvalue, cc_flag) name##Index,130compilerdirectives_common_flags(enum_of_flags)131compilerdirectives_c2_flags(enum_of_flags)132compilerdirectives_c1_flags(enum_of_flags)133number_of_flags134} flags;135136private:137bool _modified[number_of_flags]; // Records what options where set by a directive138139public:140#define flag_store_definition(name, type, dvalue, cc_flag) type name##Option;141compilerdirectives_common_flags(flag_store_definition)142compilerdirectives_c2_flags(flag_store_definition)143compilerdirectives_c1_flags(flag_store_definition)144145// Casting to get the same function signature for all setters. Used from parser.146#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; }147compilerdirectives_common_flags(set_function_definition)148compilerdirectives_c2_flags(set_function_definition)149compilerdirectives_c1_flags(set_function_definition)150151void print_intx(outputStream* st, ccstr n, intx v, bool mod) { if (mod) { st->print("%s:" INTX_FORMAT " ", n, v); } }152void print_uintx(outputStream* st, ccstr n, intx v, bool mod) { if (mod) { st->print("%s:" UINTX_FORMAT " ", n, v); } }153void print_bool(outputStream* st, ccstr n, bool v, bool mod) { if (mod) { st->print("%s:%s ", n, v ? "true" : "false"); } }154void print_double(outputStream* st, ccstr n, double v, bool mod) { if (mod) { st->print("%s:%f ", n, v); } }155void print_ccstr(outputStream* st, ccstr n, ccstr v, bool mod) { if (mod) { st->print("%s:%s ", n, v); } }156void print_ccstrlist(outputStream* st, ccstr n, ccstr v, bool mod) { print_ccstr(st, n, v, mod); }157158void print(outputStream* st) {159print_inline(st);160st->print(" ");161#define print_function_definition(name, type, dvalue, cc_flag) print_##type(st, #name, this->name##Option, true);162compilerdirectives_common_flags(print_function_definition)163compilerdirectives_c2_flags(print_function_definition)164compilerdirectives_c1_flags(print_function_definition)165st->cr();166}167};168169// Iterator of ControlIntrinsic=+_id1,-_id2,+_id3,...170//171// If disable_all is set, it accepts DisableIntrinsic and all intrinsic Ids172// appear in the list are disabled. Arguments don't have +/- prefix. eg.173// DisableIntrinsic=_id1,_id2,_id3,...174class ControlIntrinsicIter {175private:176bool _enabled;177char* _token;178char* _saved_ptr;179char* _list;180const bool _disableIntrinsic;181void next_token();182183public:184ControlIntrinsicIter(ccstrlist option, bool disable_all = false);185~ControlIntrinsicIter();186187bool is_enabled() const { return _enabled; }188const char* operator*() const { return _token; }189190ControlIntrinsicIter& operator++();191};192193class ControlIntrinsicValidator {194private:195bool _valid;196char* _bad;197198public:199ControlIntrinsicValidator(ccstrlist option, bool disable_all) : _valid(true), _bad(nullptr) {200for (ControlIntrinsicIter iter(option, disable_all); *iter != NULL && _valid; ++iter) {201if (vmIntrinsics::_none == vmIntrinsics::find_id(*iter)) {202const size_t len = MIN2<size_t>(strlen(*iter), 63) + 1; // cap len to a value we know is enough for all intrinsic names203_bad = NEW_C_HEAP_ARRAY(char, len, mtCompiler);204// strncpy always writes len characters. If the source string is shorter, the function fills the remaining bytes with NULLs.205strncpy(_bad, *iter, len);206_valid = false;207}208}209}210211~ControlIntrinsicValidator() {212if (_bad != NULL) {213FREE_C_HEAP_ARRAY(char, _bad);214}215}216217bool is_valid() const {218return _valid;219}220221const char* what() const {222return _bad;223}224};225226class CompilerDirectives : public CHeapObj<mtCompiler> {227private:228CompilerDirectives* _next;229BasicMatcher* _match;230int _ref_count;231232public:233234CompilerDirectives();235~CompilerDirectives();236237CompilerDirectives* next();238void set_next(CompilerDirectives* next) {_next = next; }239240bool match(const methodHandle& method);241BasicMatcher* match() { return _match; }242bool add_match(char* str, const char*& error_msg);243DirectiveSet* get_for(AbstractCompiler *comp);244void print(outputStream* st);245bool is_default_directive() { return _next == NULL; }246void finalize(outputStream* st);247248void inc_refcount();249void dec_refcount();250int refcount();251252DirectiveSet* _c1_store;253DirectiveSet* _c2_store;254};255256#endif // SHARE_COMPILER_COMPILERDIRECTIVES_HPP257258259