Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/compiler/compilerDirectives.hpp
40930 views
1
/*
2
* Copyright (c) 1998, 2021, 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_COMPILER_COMPILERDIRECTIVES_HPP
26
#define SHARE_COMPILER_COMPILERDIRECTIVES_HPP
27
28
#include "classfile/vmIntrinsics.hpp"
29
#include "ci/ciMetadata.hpp"
30
#include "ci/ciMethod.hpp"
31
#include "compiler/compiler_globals.hpp"
32
#include "compiler/methodMatcher.hpp"
33
#include "compiler/compilerOracle.hpp"
34
#include "utilities/exceptions.hpp"
35
#include "utilities/tribool.hpp"
36
37
// Directives flag name, type, default value, compile command name
38
#define compilerdirectives_common_flags(cflags) \
39
cflags(Enable, bool, false, Unknown) \
40
cflags(Exclude, bool, false, Unknown) \
41
cflags(BreakAtExecute, bool, false, BreakAtExecute) \
42
cflags(BreakAtCompile, bool, false, BreakAtCompile) \
43
cflags(Log, bool, LogCompilation, Unknown) \
44
cflags(PrintAssembly, bool, PrintAssembly, PrintAssembly) \
45
cflags(PrintInlining, bool, PrintInlining, PrintInlining) \
46
cflags(PrintNMethods, bool, PrintNMethods, PrintNMethods) \
47
cflags(BackgroundCompilation, bool, BackgroundCompilation, BackgroundCompilation) \
48
cflags(ReplayInline, bool, false, ReplayInline) \
49
cflags(DumpReplay, bool, false, DumpReplay) \
50
cflags(DumpInline, bool, false, DumpInline) \
51
cflags(CompilerDirectivesIgnoreCompileCommands, bool, CompilerDirectivesIgnoreCompileCommands, Unknown) \
52
cflags(DisableIntrinsic, ccstrlist, DisableIntrinsic, DisableIntrinsic) \
53
cflags(ControlIntrinsic, ccstrlist, ControlIntrinsic, ControlIntrinsic) \
54
cflags(RepeatCompilation, intx, RepeatCompilation, RepeatCompilation)
55
56
#ifdef COMPILER1
57
#define compilerdirectives_c1_flags(cflags)
58
#else
59
#define compilerdirectives_c1_flags(cflags)
60
#endif
61
62
#ifdef COMPILER2
63
#define compilerdirectives_c2_flags(cflags) \
64
cflags(BlockLayoutByFrequency, bool, BlockLayoutByFrequency, BlockLayoutByFrequency) \
65
cflags(PrintOptoAssembly, bool, PrintOptoAssembly, PrintOptoAssembly) \
66
cflags(PrintIntrinsics, bool, PrintIntrinsics, PrintIntrinsics) \
67
NOT_PRODUCT(cflags(TraceOptoPipelining, bool, TraceOptoPipelining, TraceOptoPipelining)) \
68
NOT_PRODUCT(cflags(TraceOptoOutput, bool, TraceOptoOutput, TraceOptoOutput)) \
69
NOT_PRODUCT(cflags(PrintIdeal, bool, PrintIdeal, PrintIdeal)) \
70
cflags(TraceSpilling, bool, TraceSpilling, TraceSpilling) \
71
cflags(Vectorize, bool, false, Vectorize) \
72
cflags(CloneMapDebug, bool, false, CloneMapDebug) \
73
NOT_PRODUCT(cflags(IGVPrintLevel, intx, PrintIdealGraphLevel, IGVPrintLevel)) \
74
cflags(VectorizeDebug, uintx, 0, VectorizeDebug) \
75
cflags(IncrementalInlineForceCleanup, bool, IncrementalInlineForceCleanup, IncrementalInlineForceCleanup) \
76
cflags(MaxNodeLimit, intx, MaxNodeLimit, MaxNodeLimit)
77
#else
78
#define compilerdirectives_c2_flags(cflags)
79
#endif
80
81
class AbstractCompiler;
82
class CompilerDirectives;
83
class DirectiveSet;
84
85
class DirectivesStack : AllStatic {
86
private:
87
static CompilerDirectives* _top;
88
static CompilerDirectives* _bottom;
89
static int _depth;
90
91
static void pop_inner(); // no lock version of pop
92
public:
93
static void init();
94
static DirectiveSet* getMatchingDirective(const methodHandle& mh, AbstractCompiler* comp);
95
static DirectiveSet* getDefaultDirective(AbstractCompiler* comp);
96
static void push(CompilerDirectives* directive);
97
static void pop(int count);
98
static bool check_capacity(int request_size, outputStream* st);
99
static void clear();
100
static void print(outputStream* st);
101
static void release(DirectiveSet* set);
102
static void release(CompilerDirectives* dir);
103
};
104
105
class DirectiveSet : public CHeapObj<mtCompiler> {
106
private:
107
InlineMatcher* _inlinematchers;
108
CompilerDirectives* _directive;
109
TriBoolArray<(size_t)vmIntrinsics::number_of_intrinsics(), int> _intrinsic_control_words;
110
111
public:
112
DirectiveSet(CompilerDirectives* directive);
113
~DirectiveSet();
114
void init_control_intrinsic();
115
CompilerDirectives* directive();
116
bool parse_and_add_inline(char* str, const char*& error_msg);
117
void append_inline(InlineMatcher* m);
118
bool should_inline(ciMethod* inlinee);
119
bool should_not_inline(ciMethod* inlinee);
120
void print_inline(outputStream* st);
121
DirectiveSet* compilecommand_compatibility_init(const methodHandle& method);
122
bool is_exclusive_copy() { return _directive == NULL; }
123
bool matches_inline(const methodHandle& method, int inline_action);
124
static DirectiveSet* clone(DirectiveSet const* src);
125
bool is_intrinsic_disabled(const methodHandle& method);
126
static ccstrlist canonicalize_control_intrinsic(ccstrlist option_value);
127
void finalize(outputStream* st);
128
129
typedef enum {
130
#define enum_of_flags(name, type, dvalue, cc_flag) name##Index,
131
compilerdirectives_common_flags(enum_of_flags)
132
compilerdirectives_c2_flags(enum_of_flags)
133
compilerdirectives_c1_flags(enum_of_flags)
134
number_of_flags
135
} flags;
136
137
private:
138
bool _modified[number_of_flags]; // Records what options where set by a directive
139
140
public:
141
#define flag_store_definition(name, type, dvalue, cc_flag) type name##Option;
142
compilerdirectives_common_flags(flag_store_definition)
143
compilerdirectives_c2_flags(flag_store_definition)
144
compilerdirectives_c1_flags(flag_store_definition)
145
146
// Casting to get the same function signature for all setters. Used from parser.
147
#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; }
148
compilerdirectives_common_flags(set_function_definition)
149
compilerdirectives_c2_flags(set_function_definition)
150
compilerdirectives_c1_flags(set_function_definition)
151
152
void print_intx(outputStream* st, ccstr n, intx v, bool mod) { if (mod) { st->print("%s:" INTX_FORMAT " ", n, v); } }
153
void print_uintx(outputStream* st, ccstr n, intx v, bool mod) { if (mod) { st->print("%s:" UINTX_FORMAT " ", n, v); } }
154
void print_bool(outputStream* st, ccstr n, bool v, bool mod) { if (mod) { st->print("%s:%s ", n, v ? "true" : "false"); } }
155
void print_double(outputStream* st, ccstr n, double v, bool mod) { if (mod) { st->print("%s:%f ", n, v); } }
156
void print_ccstr(outputStream* st, ccstr n, ccstr v, bool mod) { if (mod) { st->print("%s:%s ", n, v); } }
157
void print_ccstrlist(outputStream* st, ccstr n, ccstr v, bool mod) { print_ccstr(st, n, v, mod); }
158
159
void print(outputStream* st) {
160
print_inline(st);
161
st->print(" ");
162
#define print_function_definition(name, type, dvalue, cc_flag) print_##type(st, #name, this->name##Option, true);
163
compilerdirectives_common_flags(print_function_definition)
164
compilerdirectives_c2_flags(print_function_definition)
165
compilerdirectives_c1_flags(print_function_definition)
166
st->cr();
167
}
168
};
169
170
// Iterator of ControlIntrinsic=+_id1,-_id2,+_id3,...
171
//
172
// If disable_all is set, it accepts DisableIntrinsic and all intrinsic Ids
173
// appear in the list are disabled. Arguments don't have +/- prefix. eg.
174
// DisableIntrinsic=_id1,_id2,_id3,...
175
class ControlIntrinsicIter {
176
private:
177
bool _enabled;
178
char* _token;
179
char* _saved_ptr;
180
char* _list;
181
const bool _disableIntrinsic;
182
void next_token();
183
184
public:
185
ControlIntrinsicIter(ccstrlist option, bool disable_all = false);
186
~ControlIntrinsicIter();
187
188
bool is_enabled() const { return _enabled; }
189
const char* operator*() const { return _token; }
190
191
ControlIntrinsicIter& operator++();
192
};
193
194
class ControlIntrinsicValidator {
195
private:
196
bool _valid;
197
char* _bad;
198
199
public:
200
ControlIntrinsicValidator(ccstrlist option, bool disable_all) : _valid(true), _bad(nullptr) {
201
for (ControlIntrinsicIter iter(option, disable_all); *iter != NULL && _valid; ++iter) {
202
if (vmIntrinsics::_none == vmIntrinsics::find_id(*iter)) {
203
const size_t len = MIN2<size_t>(strlen(*iter), 63) + 1; // cap len to a value we know is enough for all intrinsic names
204
_bad = NEW_C_HEAP_ARRAY(char, len, mtCompiler);
205
// strncpy always writes len characters. If the source string is shorter, the function fills the remaining bytes with NULLs.
206
strncpy(_bad, *iter, len);
207
_valid = false;
208
}
209
}
210
}
211
212
~ControlIntrinsicValidator() {
213
if (_bad != NULL) {
214
FREE_C_HEAP_ARRAY(char, _bad);
215
}
216
}
217
218
bool is_valid() const {
219
return _valid;
220
}
221
222
const char* what() const {
223
return _bad;
224
}
225
};
226
227
class CompilerDirectives : public CHeapObj<mtCompiler> {
228
private:
229
CompilerDirectives* _next;
230
BasicMatcher* _match;
231
int _ref_count;
232
233
public:
234
235
CompilerDirectives();
236
~CompilerDirectives();
237
238
CompilerDirectives* next();
239
void set_next(CompilerDirectives* next) {_next = next; }
240
241
bool match(const methodHandle& method);
242
BasicMatcher* match() { return _match; }
243
bool add_match(char* str, const char*& error_msg);
244
DirectiveSet* get_for(AbstractCompiler *comp);
245
void print(outputStream* st);
246
bool is_default_directive() { return _next == NULL; }
247
void finalize(outputStream* st);
248
249
void inc_refcount();
250
void dec_refcount();
251
int refcount();
252
253
DirectiveSet* _c1_store;
254
DirectiveSet* _c2_store;
255
};
256
257
#endif // SHARE_COMPILER_COMPILERDIRECTIVES_HPP
258
259