author | stefank |
Mon, 25 Nov 2019 12:31:39 +0100 | |
changeset 59249 | 29b0d0b61615 |
parent 53244 | 9807daeb47c4 |
permissions | -rw-r--r-- |
33451
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52290
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
33451
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
4 |
* |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
8 |
* |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
13 |
* accompanied this code). |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
14 |
* |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
18 |
* |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
21 |
* questions. |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
22 |
* |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
23 |
*/ |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
24 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52290
diff
changeset
|
25 |
#ifndef SHARE_COMPILER_DIRECTIVESPARSER_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52290
diff
changeset
|
26 |
#define SHARE_COMPILER_DIRECTIVESPARSER_HPP |
33451
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
27 |
|
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
28 |
#include "utilities/json.hpp" |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
29 |
#include "compiler/compilerDirectives.hpp" |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
30 |
|
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
31 |
enum FlagType { |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
32 |
boolFlag, |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
33 |
intxFlag, |
42617
9ac2fe949f27
8170416: CompilerControl: VectorizeDebug option type is incorrect
kvn
parents:
38113
diff
changeset
|
34 |
uintxFlag, |
33451
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
35 |
doubleFlag, |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
36 |
ccstrFlag, |
33480
e4cef6796874
8138651: -XX:DisableIntrinsic matches intrinsics overly eagerly
zmajo
parents:
33451
diff
changeset
|
37 |
ccstrlistFlag, |
33451
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
38 |
UnknownFlagType |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
39 |
}; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
40 |
|
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
41 |
static const char* flag_type_names[] = { |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
42 |
"bool", |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
43 |
"int", |
42617
9ac2fe949f27
8170416: CompilerControl: VectorizeDebug option type is incorrect
kvn
parents:
38113
diff
changeset
|
44 |
"uint", |
33451
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
45 |
"double", |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
46 |
"string", |
33480
e4cef6796874
8138651: -XX:DisableIntrinsic matches intrinsics overly eagerly
zmajo
parents:
33451
diff
changeset
|
47 |
"string list", |
33451
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
48 |
"unknown" |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
49 |
}; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
50 |
|
52290 | 51 |
class DirectivesParserTest; |
52 |
||
33451
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
53 |
class DirectivesParser : public JSON { |
52290 | 54 |
friend class DirectivesParserTest; |
55 |
public: |
|
33451
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
56 |
static bool has_file(); |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
57 |
static bool parse_from_flag(); |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
58 |
static bool parse_from_file(const char* filename, outputStream* st); |
36597
ee256e343585
8150646: Add support for blocking compiles though whitebox API
simonis
parents:
35529
diff
changeset
|
59 |
static int parse_string(const char* string, outputStream* st); |
ee256e343585
8150646: Add support for blocking compiles though whitebox API
simonis
parents:
35529
diff
changeset
|
60 |
int install_directives(); |
33451
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
61 |
|
52290 | 62 |
private: |
38113
0df3b8f87cca
8155206: Internal VM test DirectiveParser_test is too verbose
stefank
parents:
36597
diff
changeset
|
63 |
DirectivesParser(const char* text, outputStream* st, bool silent); |
33451
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
64 |
~DirectivesParser(); |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
65 |
|
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
66 |
bool callback(JSON_TYPE t, JSON_VAL* v, uint level); |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
67 |
static bool parse_from_file_inner(const char* filename, outputStream* st); |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
68 |
|
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
69 |
// types of "keys". i.e recognized <key>:<value> pairs in our JSON syntax |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
70 |
typedef enum { |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
71 |
type_c1, |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
72 |
type_c2, |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
73 |
type_enable, |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
74 |
type_preset, |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
75 |
type_match, |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
76 |
type_inline, |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
77 |
|
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
78 |
// After here, there is no correlation between |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
79 |
// keytype and keys array |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
80 |
//type_strategy, |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
81 |
type_flag, |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
82 |
//type_dir, |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
83 |
|
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
84 |
// Synthetic. |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
85 |
type_dir_array, |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
86 |
type_directives, |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
87 |
type_value_array |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
88 |
} keytype; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
89 |
|
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
90 |
// name, type, dtd info and maybe a setter |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
91 |
// this is how we map key-values |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
92 |
typedef struct { |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
93 |
const char *name; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
94 |
keytype type; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
95 |
uint allow_array_value : 1; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
96 |
uint allowedmask; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
97 |
void (DirectiveSet::*set)(void* arg); |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
98 |
FlagType flag_type; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
99 |
} key; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
100 |
|
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
101 |
// Array with valid keys for the directive file |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
102 |
static const key keys[]; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
103 |
// Marker for outermost moosewings/array |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
104 |
static const key dir_array_key; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
105 |
// Marker for a directives set (these are "implicit" objects, as in not named) |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
106 |
static const key dir_key; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
107 |
// Marker for a multi value |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
108 |
static const key value_array_key; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
109 |
|
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
110 |
// A compiler directive shouldn't be able to use more than 5 stack slots. |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
111 |
// Example of max stack usage: |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
112 |
// depth 1: type_dir_array [ |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
113 |
// depth 2: type_directives { |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
114 |
// depth 3: type_c1 c1: { |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
115 |
// depth 4: type_inline inline: |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
116 |
// depth 5: type_value_array [ ... |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
117 |
static const uint MAX_DEPTH = 5; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
118 |
const key* stack[MAX_DEPTH]; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
119 |
uint depth; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
120 |
|
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
121 |
bool push_key(const char* str, size_t len); |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
122 |
bool push_key(const key* k); |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
123 |
const key* current_key(); |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
124 |
const key* pop_key(); |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
125 |
static const key* lookup_key(const char* s, size_t len); |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
126 |
|
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
127 |
bool set_option(JSON_TYPE t, JSON_VAL* v); |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
128 |
bool set_option_flag(JSON_TYPE t, JSON_VAL* v, const key* option_key, DirectiveSet* set); |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
129 |
|
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
130 |
CompilerDirectives* current_directive; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
131 |
DirectiveSet* current_directiveset; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
132 |
|
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
133 |
void push_tmp(CompilerDirectives* dir); |
35129
8b93709bf4e5
8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents:
33480
diff
changeset
|
134 |
void clean_tmp(); |
33451
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
135 |
CompilerDirectives* pop_tmp(); |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
136 |
CompilerDirectives* _tmp_top; // temporary storage for dirs while parsing |
35129
8b93709bf4e5
8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents:
33480
diff
changeset
|
137 |
int _tmp_depth; // Number of directives that has been parsed but not installed. |
33451
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
138 |
|
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
139 |
static uint mask(keytype kt); |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
140 |
}; |
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff
changeset
|
141 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52290
diff
changeset
|
142 |
#endif // SHARE_COMPILER_DIRECTIVESPARSER_HPP |