author | coleenp |
Wed, 21 May 2014 14:36:18 -0400 | |
changeset 24658 | e41df2fc6e87 |
parent 24424 | 2658d7834c6e |
child 25949 | 34557722059b |
permissions | -rw-r--r-- |
1 | 1 |
/* |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
23185
diff
changeset
|
2 |
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4584
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4584
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4584
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "compiler/compilerOracle.hpp" |
|
27 |
#include "memory/allocation.inline.hpp" |
|
28 |
#include "memory/oopFactory.hpp" |
|
29 |
#include "memory/resourceArea.hpp" |
|
30 |
#include "oops/klass.hpp" |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13202
diff
changeset
|
31 |
#include "oops/method.hpp" |
7397 | 32 |
#include "oops/oop.inline.hpp" |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
33 |
#include "oops/symbol.hpp" |
7397 | 34 |
#include "runtime/handles.inline.hpp" |
35 |
#include "runtime/jniHandles.hpp" |
|
1 | 36 |
|
13195 | 37 |
class MethodMatcher : public CHeapObj<mtCompiler> { |
1 | 38 |
public: |
39 |
enum Mode { |
|
40 |
Exact, |
|
41 |
Prefix = 1, |
|
42 |
Suffix = 2, |
|
43 |
Substring = Prefix | Suffix, |
|
44 |
Any, |
|
45 |
Unknown = -1 |
|
46 |
}; |
|
47 |
||
48 |
protected: |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
49 |
Symbol* _class_name; |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
50 |
Symbol* _method_name; |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
51 |
Symbol* _signature; |
1 | 52 |
Mode _class_mode; |
53 |
Mode _method_mode; |
|
54 |
MethodMatcher* _next; |
|
55 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
56 |
static bool match(Symbol* candidate, Symbol* match, Mode match_mode); |
1 | 57 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
58 |
Symbol* class_name() const { return _class_name; } |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
59 |
Symbol* method_name() const { return _method_name; } |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
60 |
Symbol* signature() const { return _signature; } |
1 | 61 |
|
62 |
public: |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
63 |
MethodMatcher(Symbol* class_name, Mode class_mode, |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
64 |
Symbol* method_name, Mode method_mode, |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
65 |
Symbol* signature, MethodMatcher* next); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
66 |
MethodMatcher(Symbol* class_name, Symbol* method_name, MethodMatcher* next); |
1 | 67 |
|
68 |
// utility method |
|
69 |
MethodMatcher* find(methodHandle method) { |
|
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
14147
diff
changeset
|
70 |
Symbol* class_name = method->method_holder()->name(); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
71 |
Symbol* method_name = method->name(); |
1 | 72 |
for (MethodMatcher* current = this; current != NULL; current = current->_next) { |
73 |
if (match(class_name, current->class_name(), current->_class_mode) && |
|
74 |
match(method_name, current->method_name(), current->_method_mode) && |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
75 |
(current->signature() == NULL || current->signature() == method->signature())) { |
1 | 76 |
return current; |
77 |
} |
|
78 |
} |
|
79 |
return NULL; |
|
80 |
} |
|
81 |
||
82 |
bool match(methodHandle method) { |
|
83 |
return find(method) != NULL; |
|
84 |
} |
|
85 |
||
86 |
MethodMatcher* next() const { return _next; } |
|
87 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
88 |
static void print_symbol(Symbol* h, Mode mode) { |
1 | 89 |
ResourceMark rm; |
90 |
||
91 |
if (mode == Suffix || mode == Substring || mode == Any) { |
|
92 |
tty->print("*"); |
|
93 |
} |
|
94 |
if (mode != Any) { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
95 |
h->print_symbol_on(tty); |
1 | 96 |
} |
97 |
if (mode == Prefix || mode == Substring) { |
|
98 |
tty->print("*"); |
|
99 |
} |
|
100 |
} |
|
101 |
||
102 |
void print_base() { |
|
103 |
print_symbol(class_name(), _class_mode); |
|
104 |
tty->print("."); |
|
105 |
print_symbol(method_name(), _method_mode); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
106 |
if (signature() != NULL) { |
1 | 107 |
tty->print(" "); |
108 |
signature()->print_symbol_on(tty); |
|
109 |
} |
|
110 |
} |
|
111 |
||
112 |
virtual void print() { |
|
113 |
print_base(); |
|
114 |
tty->cr(); |
|
115 |
} |
|
116 |
}; |
|
117 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
118 |
MethodMatcher::MethodMatcher(Symbol* class_name, Symbol* method_name, MethodMatcher* next) { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
119 |
_class_name = class_name; |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
120 |
_method_name = method_name; |
1 | 121 |
_next = next; |
122 |
_class_mode = MethodMatcher::Exact; |
|
123 |
_method_mode = MethodMatcher::Exact; |
|
124 |
_signature = NULL; |
|
125 |
} |
|
126 |
||
127 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
128 |
MethodMatcher::MethodMatcher(Symbol* class_name, Mode class_mode, |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
129 |
Symbol* method_name, Mode method_mode, |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
130 |
Symbol* signature, MethodMatcher* next): |
1 | 131 |
_class_mode(class_mode) |
132 |
, _method_mode(method_mode) |
|
133 |
, _next(next) |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
134 |
, _class_name(class_name) |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
135 |
, _method_name(method_name) |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
136 |
, _signature(signature) { |
1 | 137 |
} |
138 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
139 |
bool MethodMatcher::match(Symbol* candidate, Symbol* match, Mode match_mode) { |
1 | 140 |
if (match_mode == Any) { |
141 |
return true; |
|
142 |
} |
|
143 |
||
144 |
if (match_mode == Exact) { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
145 |
return candidate == match; |
1 | 146 |
} |
147 |
||
148 |
ResourceMark rm; |
|
149 |
const char * candidate_string = candidate->as_C_string(); |
|
150 |
const char * match_string = match->as_C_string(); |
|
151 |
||
152 |
switch (match_mode) { |
|
153 |
case Prefix: |
|
154 |
return strstr(candidate_string, match_string) == candidate_string; |
|
155 |
||
156 |
case Suffix: { |
|
157 |
size_t clen = strlen(candidate_string); |
|
158 |
size_t mlen = strlen(match_string); |
|
159 |
return clen >= mlen && strcmp(candidate_string + clen - mlen, match_string) == 0; |
|
160 |
} |
|
161 |
||
162 |
case Substring: |
|
163 |
return strstr(candidate_string, match_string) != NULL; |
|
164 |
||
165 |
default: |
|
166 |
return false; |
|
167 |
} |
|
168 |
} |
|
169 |
||
170 |
||
171 |
class MethodOptionMatcher: public MethodMatcher { |
|
172 |
const char * option; |
|
173 |
public: |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
174 |
MethodOptionMatcher(Symbol* class_name, Mode class_mode, |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
175 |
Symbol* method_name, Mode method_mode, |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
176 |
Symbol* signature, const char * opt, MethodMatcher* next): |
1 | 177 |
MethodMatcher(class_name, class_mode, method_name, method_mode, signature, next) { |
178 |
option = opt; |
|
179 |
} |
|
180 |
||
181 |
bool match(methodHandle method, const char* opt) { |
|
182 |
MethodOptionMatcher* current = this; |
|
183 |
while (current != NULL) { |
|
184 |
current = (MethodOptionMatcher*)current->find(method); |
|
185 |
if (current == NULL) { |
|
186 |
return false; |
|
187 |
} |
|
188 |
if (strcmp(current->option, opt) == 0) { |
|
189 |
return true; |
|
190 |
} |
|
191 |
current = current->next(); |
|
192 |
} |
|
193 |
return false; |
|
194 |
} |
|
195 |
||
196 |
MethodOptionMatcher* next() { |
|
197 |
return (MethodOptionMatcher*)_next; |
|
198 |
} |
|
199 |
||
200 |
virtual void print() { |
|
201 |
print_base(); |
|
202 |
tty->print(" %s", option); |
|
203 |
tty->cr(); |
|
204 |
} |
|
205 |
}; |
|
206 |
||
207 |
||
208 |
||
209 |
// this must parallel the command_names below |
|
210 |
enum OracleCommand { |
|
211 |
UnknownCommand = -1, |
|
212 |
OracleFirstCommand = 0, |
|
213 |
BreakCommand = OracleFirstCommand, |
|
214 |
PrintCommand, |
|
215 |
ExcludeCommand, |
|
216 |
InlineCommand, |
|
217 |
DontInlineCommand, |
|
218 |
CompileOnlyCommand, |
|
219 |
LogCommand, |
|
220 |
OptionCommand, |
|
221 |
QuietCommand, |
|
222 |
HelpCommand, |
|
223 |
OracleCommandCount |
|
224 |
}; |
|
225 |
||
226 |
// this must parallel the enum OracleCommand |
|
227 |
static const char * command_names[] = { |
|
228 |
"break", |
|
229 |
"print", |
|
230 |
"exclude", |
|
231 |
"inline", |
|
232 |
"dontinline", |
|
233 |
"compileonly", |
|
234 |
"log", |
|
235 |
"option", |
|
236 |
"quiet", |
|
237 |
"help" |
|
238 |
}; |
|
239 |
||
240 |
class MethodMatcher; |
|
241 |
static MethodMatcher* lists[OracleCommandCount] = { 0, }; |
|
242 |
||
243 |
||
244 |
static bool check_predicate(OracleCommand command, methodHandle method) { |
|
245 |
return ((lists[command] != NULL) && |
|
246 |
!method.is_null() && |
|
247 |
lists[command]->match(method)); |
|
248 |
} |
|
249 |
||
250 |
||
251 |
static MethodMatcher* add_predicate(OracleCommand command, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
252 |
Symbol* class_name, MethodMatcher::Mode c_mode, |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
253 |
Symbol* method_name, MethodMatcher::Mode m_mode, |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
254 |
Symbol* signature) { |
1 | 255 |
assert(command != OptionCommand, "must use add_option_string"); |
256 |
if (command == LogCommand && !LogCompilation && lists[LogCommand] == NULL) |
|
257 |
tty->print_cr("Warning: +LogCompilation must be enabled in order for individual methods to be logged."); |
|
258 |
lists[command] = new MethodMatcher(class_name, c_mode, method_name, m_mode, signature, lists[command]); |
|
259 |
return lists[command]; |
|
260 |
} |
|
261 |
||
262 |
||
263 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
264 |
static MethodMatcher* add_option_string(Symbol* class_name, MethodMatcher::Mode c_mode, |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
265 |
Symbol* method_name, MethodMatcher::Mode m_mode, |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
266 |
Symbol* signature, |
1 | 267 |
const char* option) { |
268 |
lists[OptionCommand] = new MethodOptionMatcher(class_name, c_mode, method_name, m_mode, |
|
269 |
signature, option, lists[OptionCommand]); |
|
270 |
return lists[OptionCommand]; |
|
271 |
} |
|
272 |
||
273 |
||
274 |
bool CompilerOracle::has_option_string(methodHandle method, const char* option) { |
|
275 |
return lists[OptionCommand] != NULL && |
|
276 |
((MethodOptionMatcher*)lists[OptionCommand])->match(method, option); |
|
277 |
} |
|
278 |
||
279 |
||
280 |
bool CompilerOracle::should_exclude(methodHandle method, bool& quietly) { |
|
281 |
quietly = true; |
|
282 |
if (lists[ExcludeCommand] != NULL) { |
|
283 |
if (lists[ExcludeCommand]->match(method)) { |
|
284 |
quietly = _quiet; |
|
285 |
return true; |
|
286 |
} |
|
287 |
} |
|
288 |
||
289 |
if (lists[CompileOnlyCommand] != NULL) { |
|
290 |
return !lists[CompileOnlyCommand]->match(method); |
|
291 |
} |
|
292 |
return false; |
|
293 |
} |
|
294 |
||
295 |
||
296 |
bool CompilerOracle::should_inline(methodHandle method) { |
|
297 |
return (check_predicate(InlineCommand, method)); |
|
298 |
} |
|
299 |
||
300 |
||
301 |
bool CompilerOracle::should_not_inline(methodHandle method) { |
|
302 |
return (check_predicate(DontInlineCommand, method)); |
|
303 |
} |
|
304 |
||
305 |
||
306 |
bool CompilerOracle::should_print(methodHandle method) { |
|
307 |
return (check_predicate(PrintCommand, method)); |
|
308 |
} |
|
309 |
||
24658
e41df2fc6e87
8042727: nsk/jdb/unwatch/unwatch001 crash in InstanceKlass::methods_do(void (*)(Method*))
coleenp
parents:
24424
diff
changeset
|
310 |
bool CompilerOracle::should_print_methods() { |
e41df2fc6e87
8042727: nsk/jdb/unwatch/unwatch001 crash in InstanceKlass::methods_do(void (*)(Method*))
coleenp
parents:
24424
diff
changeset
|
311 |
return lists[PrintCommand] != NULL; |
e41df2fc6e87
8042727: nsk/jdb/unwatch/unwatch001 crash in InstanceKlass::methods_do(void (*)(Method*))
coleenp
parents:
24424
diff
changeset
|
312 |
} |
1 | 313 |
|
314 |
bool CompilerOracle::should_log(methodHandle method) { |
|
315 |
if (!LogCompilation) return false; |
|
316 |
if (lists[LogCommand] == NULL) return true; // by default, log all |
|
317 |
return (check_predicate(LogCommand, method)); |
|
318 |
} |
|
319 |
||
320 |
||
321 |
bool CompilerOracle::should_break_at(methodHandle method) { |
|
322 |
return check_predicate(BreakCommand, method); |
|
323 |
} |
|
324 |
||
325 |
||
326 |
static OracleCommand parse_command_name(const char * line, int* bytes_read) { |
|
327 |
assert(ARRAY_SIZE(command_names) == OracleCommandCount, |
|
328 |
"command_names size mismatch"); |
|
329 |
||
330 |
*bytes_read = 0; |
|
7701
766eb9258574
6765546: Wrong sscanf used to parse CompilerOracle command >= 32 characters could lead to crash
never
parents:
7397
diff
changeset
|
331 |
char command[33]; |
1 | 332 |
int result = sscanf(line, "%32[a-z]%n", command, bytes_read); |
333 |
for (uint i = 0; i < ARRAY_SIZE(command_names); i++) { |
|
334 |
if (strcmp(command, command_names[i]) == 0) { |
|
335 |
return (OracleCommand)i; |
|
336 |
} |
|
337 |
} |
|
338 |
return UnknownCommand; |
|
339 |
} |
|
340 |
||
341 |
||
342 |
static void usage() { |
|
343 |
tty->print_cr(" CompileCommand and the CompilerOracle allows simple control over"); |
|
344 |
tty->print_cr(" what's allowed to be compiled. The standard supported directives"); |
|
345 |
tty->print_cr(" are exclude and compileonly. The exclude directive stops a method"); |
|
346 |
tty->print_cr(" from being compiled and compileonly excludes all methods except for"); |
|
347 |
tty->print_cr(" the ones mentioned by compileonly directives. The basic form of"); |
|
348 |
tty->print_cr(" all commands is a command name followed by the name of the method"); |
|
349 |
tty->print_cr(" in one of two forms: the standard class file format as in"); |
|
350 |
tty->print_cr(" class/name.methodName or the PrintCompilation format"); |
|
351 |
tty->print_cr(" class.name::methodName. The method name can optionally be followed"); |
|
352 |
tty->print_cr(" by a space then the signature of the method in the class file"); |
|
353 |
tty->print_cr(" format. Otherwise the directive applies to all methods with the"); |
|
354 |
tty->print_cr(" same name and class regardless of signature. Leading and trailing"); |
|
355 |
tty->print_cr(" *'s in the class and/or method name allows a small amount of"); |
|
356 |
tty->print_cr(" wildcarding. "); |
|
357 |
tty->cr(); |
|
358 |
tty->print_cr(" Examples:"); |
|
359 |
tty->cr(); |
|
360 |
tty->print_cr(" exclude java/lang/StringBuffer.append"); |
|
361 |
tty->print_cr(" compileonly java/lang/StringBuffer.toString ()Ljava/lang/String;"); |
|
362 |
tty->print_cr(" exclude java/lang/String*.*"); |
|
363 |
tty->print_cr(" exclude *.toString"); |
|
364 |
} |
|
365 |
||
366 |
||
367 |
// The characters allowed in a class or method name. All characters > 0x7f |
|
368 |
// are allowed in order to handle obfuscated class files (e.g. Volano) |
|
369 |
#define RANGEBASE "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_<>" \ |
|
370 |
"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" \ |
|
371 |
"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" \ |
|
372 |
"\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" \ |
|
373 |
"\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" \ |
|
374 |
"\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf" \ |
|
375 |
"\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf" \ |
|
376 |
"\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef" \ |
|
377 |
"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff" |
|
378 |
||
379 |
#define RANGE0 "[*" RANGEBASE "]" |
|
380 |
#define RANGESLASH "[*" RANGEBASE "/]" |
|
381 |
||
382 |
static MethodMatcher::Mode check_mode(char name[], const char*& error_msg) { |
|
383 |
int match = MethodMatcher::Exact; |
|
4584
e2a449e8cc6f
6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents:
1
diff
changeset
|
384 |
while (name[0] == '*') { |
1 | 385 |
match |= MethodMatcher::Suffix; |
386 |
strcpy(name, name + 1); |
|
387 |
} |
|
388 |
||
4584
e2a449e8cc6f
6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents:
1
diff
changeset
|
389 |
if (strcmp(name, "*") == 0) return MethodMatcher::Any; |
e2a449e8cc6f
6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents:
1
diff
changeset
|
390 |
|
1 | 391 |
size_t len = strlen(name); |
4584
e2a449e8cc6f
6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents:
1
diff
changeset
|
392 |
while (len > 0 && name[len - 1] == '*') { |
1 | 393 |
match |= MethodMatcher::Prefix; |
4584
e2a449e8cc6f
6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents:
1
diff
changeset
|
394 |
name[--len] = '\0'; |
1 | 395 |
} |
396 |
||
397 |
if (strstr(name, "*") != NULL) { |
|
398 |
error_msg = " Embedded * not allowed"; |
|
399 |
return MethodMatcher::Unknown; |
|
400 |
} |
|
401 |
return (MethodMatcher::Mode)match; |
|
402 |
} |
|
403 |
||
404 |
static bool scan_line(const char * line, |
|
405 |
char class_name[], MethodMatcher::Mode* c_mode, |
|
406 |
char method_name[], MethodMatcher::Mode* m_mode, |
|
407 |
int* bytes_read, const char*& error_msg) { |
|
408 |
*bytes_read = 0; |
|
409 |
error_msg = NULL; |
|
23185 | 410 |
if (2 == sscanf(line, "%*[ \t]%255" RANGESLASH "%*[ ]" "%255" RANGE0 "%n", class_name, method_name, bytes_read)) { |
411 |
*c_mode = check_mode(class_name, error_msg); |
|
412 |
*m_mode = check_mode(method_name, error_msg); |
|
413 |
return *c_mode != MethodMatcher::Unknown && *m_mode != MethodMatcher::Unknown; |
|
1 | 414 |
} |
415 |
return false; |
|
416 |
} |
|
417 |
||
418 |
||
419 |
||
420 |
void CompilerOracle::parse_from_line(char* line) { |
|
421 |
if (line[0] == '\0') return; |
|
422 |
if (line[0] == '#') return; |
|
423 |
||
424 |
bool have_colon = (strstr(line, "::") != NULL); |
|
425 |
for (char* lp = line; *lp != '\0'; lp++) { |
|
426 |
// Allow '.' to separate the class name from the method name. |
|
427 |
// This is the preferred spelling of methods: |
|
428 |
// exclude java/lang/String.indexOf(I)I |
|
429 |
// Allow ',' for spaces (eases command line quoting). |
|
430 |
// exclude,java/lang/String.indexOf |
|
431 |
// For backward compatibility, allow space as separator also. |
|
432 |
// exclude java/lang/String indexOf |
|
433 |
// exclude,java/lang/String,indexOf |
|
434 |
// For easy cut-and-paste of method names, allow VM output format |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13202
diff
changeset
|
435 |
// as produced by Method::print_short_name: |
1 | 436 |
// exclude java.lang.String::indexOf |
437 |
// For simple implementation convenience here, convert them all to space. |
|
438 |
if (have_colon) { |
|
439 |
if (*lp == '.') *lp = '/'; // dots build the package prefix |
|
440 |
if (*lp == ':') *lp = ' '; |
|
441 |
} |
|
442 |
if (*lp == ',' || *lp == '.') *lp = ' '; |
|
443 |
} |
|
444 |
||
445 |
char* original_line = line; |
|
446 |
int bytes_read; |
|
447 |
OracleCommand command = parse_command_name(line, &bytes_read); |
|
448 |
line += bytes_read; |
|
449 |
||
7701
766eb9258574
6765546: Wrong sscanf used to parse CompilerOracle command >= 32 characters could lead to crash
never
parents:
7397
diff
changeset
|
450 |
if (command == UnknownCommand) { |
766eb9258574
6765546: Wrong sscanf used to parse CompilerOracle command >= 32 characters could lead to crash
never
parents:
7397
diff
changeset
|
451 |
tty->print_cr("CompilerOracle: unrecognized line"); |
766eb9258574
6765546: Wrong sscanf used to parse CompilerOracle command >= 32 characters could lead to crash
never
parents:
7397
diff
changeset
|
452 |
tty->print_cr(" \"%s\"", original_line); |
766eb9258574
6765546: Wrong sscanf used to parse CompilerOracle command >= 32 characters could lead to crash
never
parents:
7397
diff
changeset
|
453 |
return; |
766eb9258574
6765546: Wrong sscanf used to parse CompilerOracle command >= 32 characters could lead to crash
never
parents:
7397
diff
changeset
|
454 |
} |
766eb9258574
6765546: Wrong sscanf used to parse CompilerOracle command >= 32 characters could lead to crash
never
parents:
7397
diff
changeset
|
455 |
|
1 | 456 |
if (command == QuietCommand) { |
457 |
_quiet = true; |
|
458 |
return; |
|
459 |
} |
|
460 |
||
461 |
if (command == HelpCommand) { |
|
462 |
usage(); |
|
463 |
return; |
|
464 |
} |
|
465 |
||
466 |
MethodMatcher::Mode c_match = MethodMatcher::Exact; |
|
467 |
MethodMatcher::Mode m_match = MethodMatcher::Exact; |
|
468 |
char class_name[256]; |
|
469 |
char method_name[256]; |
|
470 |
char sig[1024]; |
|
471 |
char errorbuf[1024]; |
|
472 |
const char* error_msg = NULL; |
|
473 |
MethodMatcher* match = NULL; |
|
474 |
||
475 |
if (scan_line(line, class_name, &c_match, method_name, &m_match, &bytes_read, error_msg)) { |
|
476 |
EXCEPTION_MARK; |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
477 |
Symbol* c_name = SymbolTable::new_symbol(class_name, CHECK); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
478 |
Symbol* m_name = SymbolTable::new_symbol(method_name, CHECK); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
479 |
Symbol* signature = NULL; |
1 | 480 |
|
481 |
line += bytes_read; |
|
482 |
// there might be a signature following the method. |
|
483 |
// signatures always begin with ( so match that by hand |
|
7701
766eb9258574
6765546: Wrong sscanf used to parse CompilerOracle command >= 32 characters could lead to crash
never
parents:
7397
diff
changeset
|
484 |
if (1 == sscanf(line, "%*[ \t](%254[[);/" RANGEBASE "]%n", sig + 1, &bytes_read)) { |
1 | 485 |
sig[0] = '('; |
486 |
line += bytes_read; |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
487 |
signature = SymbolTable::new_symbol(sig, CHECK); |
1 | 488 |
} |
489 |
||
490 |
if (command == OptionCommand) { |
|
491 |
// Look for trailing options to support |
|
492 |
// ciMethod::has_option("string") to control features in the |
|
493 |
// compiler. Multiple options may follow the method name. |
|
494 |
char option[256]; |
|
495 |
while (sscanf(line, "%*[ \t]%255[a-zA-Z0-9]%n", option, &bytes_read) == 1) { |
|
496 |
if (match != NULL && !_quiet) { |
|
497 |
// Print out the last match added |
|
498 |
tty->print("CompilerOracle: %s ", command_names[command]); |
|
499 |
match->print(); |
|
500 |
} |
|
501 |
match = add_option_string(c_name, c_match, m_name, m_match, signature, strdup(option)); |
|
502 |
line += bytes_read; |
|
503 |
} |
|
504 |
} else { |
|
505 |
bytes_read = 0; |
|
506 |
sscanf(line, "%*[ \t]%n", &bytes_read); |
|
507 |
if (line[bytes_read] != '\0') { |
|
508 |
jio_snprintf(errorbuf, sizeof(errorbuf), " Unrecognized text after command: %s", line); |
|
509 |
error_msg = errorbuf; |
|
510 |
} else { |
|
511 |
match = add_predicate(command, c_name, c_match, m_name, m_match, signature); |
|
512 |
} |
|
513 |
} |
|
514 |
} |
|
515 |
||
516 |
if (match != NULL) { |
|
517 |
if (!_quiet) { |
|
14828
bb9dffedf46c
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
14391
diff
changeset
|
518 |
ResourceMark rm; |
1 | 519 |
tty->print("CompilerOracle: %s ", command_names[command]); |
520 |
match->print(); |
|
521 |
} |
|
522 |
} else { |
|
523 |
tty->print_cr("CompilerOracle: unrecognized line"); |
|
524 |
tty->print_cr(" \"%s\"", original_line); |
|
525 |
if (error_msg != NULL) { |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
23185
diff
changeset
|
526 |
tty->print_cr("%s", error_msg); |
1 | 527 |
} |
528 |
} |
|
529 |
} |
|
530 |
||
13194
603ef19adcb8
7167142: Consider a warning when finding a .hotspotrc or .hotspot_compiler file that isn't used
kamg
parents:
12981
diff
changeset
|
531 |
static const char* default_cc_file = ".hotspot_compiler"; |
603ef19adcb8
7167142: Consider a warning when finding a .hotspotrc or .hotspot_compiler file that isn't used
kamg
parents:
12981
diff
changeset
|
532 |
|
1 | 533 |
static const char* cc_file() { |
12981
b557c10f5444
7110720: Issue with vm config file loadingIssue with vm config file loading
kamg
parents:
8921
diff
changeset
|
534 |
#ifdef ASSERT |
1 | 535 |
if (CompileCommandFile == NULL) |
13194
603ef19adcb8
7167142: Consider a warning when finding a .hotspotrc or .hotspot_compiler file that isn't used
kamg
parents:
12981
diff
changeset
|
536 |
return default_cc_file; |
12981
b557c10f5444
7110720: Issue with vm config file loadingIssue with vm config file loading
kamg
parents:
8921
diff
changeset
|
537 |
#endif |
1 | 538 |
return CompileCommandFile; |
539 |
} |
|
12981
b557c10f5444
7110720: Issue with vm config file loadingIssue with vm config file loading
kamg
parents:
8921
diff
changeset
|
540 |
|
b557c10f5444
7110720: Issue with vm config file loadingIssue with vm config file loading
kamg
parents:
8921
diff
changeset
|
541 |
bool CompilerOracle::has_command_file() { |
b557c10f5444
7110720: Issue with vm config file loadingIssue with vm config file loading
kamg
parents:
8921
diff
changeset
|
542 |
return cc_file() != NULL; |
b557c10f5444
7110720: Issue with vm config file loadingIssue with vm config file loading
kamg
parents:
8921
diff
changeset
|
543 |
} |
b557c10f5444
7110720: Issue with vm config file loadingIssue with vm config file loading
kamg
parents:
8921
diff
changeset
|
544 |
|
1 | 545 |
bool CompilerOracle::_quiet = false; |
546 |
||
547 |
void CompilerOracle::parse_from_file() { |
|
12981
b557c10f5444
7110720: Issue with vm config file loadingIssue with vm config file loading
kamg
parents:
8921
diff
changeset
|
548 |
assert(has_command_file(), "command file must be specified"); |
1 | 549 |
FILE* stream = fopen(cc_file(), "rt"); |
550 |
if (stream == NULL) return; |
|
551 |
||
552 |
char token[1024]; |
|
553 |
int pos = 0; |
|
554 |
int c = getc(stream); |
|
14139 | 555 |
while(c != EOF && pos < (int)(sizeof(token)-1)) { |
1 | 556 |
if (c == '\n') { |
557 |
token[pos++] = '\0'; |
|
558 |
parse_from_line(token); |
|
559 |
pos = 0; |
|
560 |
} else { |
|
561 |
token[pos++] = c; |
|
562 |
} |
|
563 |
c = getc(stream); |
|
564 |
} |
|
565 |
token[pos++] = '\0'; |
|
566 |
parse_from_line(token); |
|
567 |
||
568 |
fclose(stream); |
|
569 |
} |
|
570 |
||
571 |
void CompilerOracle::parse_from_string(const char* str, void (*parse_line)(char*)) { |
|
572 |
char token[1024]; |
|
573 |
int pos = 0; |
|
574 |
const char* sp = str; |
|
575 |
int c = *sp++; |
|
14139 | 576 |
while (c != '\0' && pos < (int)(sizeof(token)-1)) { |
1 | 577 |
if (c == '\n') { |
578 |
token[pos++] = '\0'; |
|
579 |
parse_line(token); |
|
580 |
pos = 0; |
|
581 |
} else { |
|
582 |
token[pos++] = c; |
|
583 |
} |
|
584 |
c = *sp++; |
|
585 |
} |
|
586 |
token[pos++] = '\0'; |
|
587 |
parse_line(token); |
|
588 |
} |
|
589 |
||
590 |
void CompilerOracle::append_comment_to_file(const char* message) { |
|
12981
b557c10f5444
7110720: Issue with vm config file loadingIssue with vm config file loading
kamg
parents:
8921
diff
changeset
|
591 |
assert(has_command_file(), "command file must be specified"); |
1 | 592 |
fileStream stream(fopen(cc_file(), "at")); |
593 |
stream.print("# "); |
|
594 |
for (int index = 0; message[index] != '\0'; index++) { |
|
595 |
stream.put(message[index]); |
|
596 |
if (message[index] == '\n') stream.print("# "); |
|
597 |
} |
|
598 |
stream.cr(); |
|
599 |
} |
|
600 |
||
601 |
void CompilerOracle::append_exclude_to_file(methodHandle method) { |
|
12981
b557c10f5444
7110720: Issue with vm config file loadingIssue with vm config file loading
kamg
parents:
8921
diff
changeset
|
602 |
assert(has_command_file(), "command file must be specified"); |
1 | 603 |
fileStream stream(fopen(cc_file(), "at")); |
604 |
stream.print("exclude "); |
|
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
14147
diff
changeset
|
605 |
method->method_holder()->name()->print_symbol_on(&stream); |
1 | 606 |
stream.print("."); |
607 |
method->name()->print_symbol_on(&stream); |
|
608 |
method->signature()->print_symbol_on(&stream); |
|
609 |
stream.cr(); |
|
610 |
stream.cr(); |
|
611 |
} |
|
612 |
||
613 |
||
614 |
void compilerOracle_init() { |
|
615 |
CompilerOracle::parse_from_string(CompileCommand, CompilerOracle::parse_from_line); |
|
616 |
CompilerOracle::parse_from_string(CompileOnly, CompilerOracle::parse_compile_only); |
|
12981
b557c10f5444
7110720: Issue with vm config file loadingIssue with vm config file loading
kamg
parents:
8921
diff
changeset
|
617 |
if (CompilerOracle::has_command_file()) { |
b557c10f5444
7110720: Issue with vm config file loadingIssue with vm config file loading
kamg
parents:
8921
diff
changeset
|
618 |
CompilerOracle::parse_from_file(); |
13194
603ef19adcb8
7167142: Consider a warning when finding a .hotspotrc or .hotspot_compiler file that isn't used
kamg
parents:
12981
diff
changeset
|
619 |
} else { |
603ef19adcb8
7167142: Consider a warning when finding a .hotspotrc or .hotspot_compiler file that isn't used
kamg
parents:
12981
diff
changeset
|
620 |
struct stat buf; |
603ef19adcb8
7167142: Consider a warning when finding a .hotspotrc or .hotspot_compiler file that isn't used
kamg
parents:
12981
diff
changeset
|
621 |
if (os::stat(default_cc_file, &buf) == 0) { |
603ef19adcb8
7167142: Consider a warning when finding a .hotspotrc or .hotspot_compiler file that isn't used
kamg
parents:
12981
diff
changeset
|
622 |
warning("%s file is present but has been ignored. " |
603ef19adcb8
7167142: Consider a warning when finding a .hotspotrc or .hotspot_compiler file that isn't used
kamg
parents:
12981
diff
changeset
|
623 |
"Run with -XX:CompileCommandFile=%s to load the file.", |
603ef19adcb8
7167142: Consider a warning when finding a .hotspotrc or .hotspot_compiler file that isn't used
kamg
parents:
12981
diff
changeset
|
624 |
default_cc_file, default_cc_file); |
603ef19adcb8
7167142: Consider a warning when finding a .hotspotrc or .hotspot_compiler file that isn't used
kamg
parents:
12981
diff
changeset
|
625 |
} |
12981
b557c10f5444
7110720: Issue with vm config file loadingIssue with vm config file loading
kamg
parents:
8921
diff
changeset
|
626 |
} |
4584
e2a449e8cc6f
6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents:
1
diff
changeset
|
627 |
if (lists[PrintCommand] != NULL) { |
e2a449e8cc6f
6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents:
1
diff
changeset
|
628 |
if (PrintAssembly) { |
13194
603ef19adcb8
7167142: Consider a warning when finding a .hotspotrc or .hotspot_compiler file that isn't used
kamg
parents:
12981
diff
changeset
|
629 |
warning("CompileCommand and/or %s file contains 'print' commands, but PrintAssembly is also enabled", default_cc_file); |
4584
e2a449e8cc6f
6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents:
1
diff
changeset
|
630 |
} else if (FLAG_IS_DEFAULT(DebugNonSafepoints)) { |
e2a449e8cc6f
6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents:
1
diff
changeset
|
631 |
warning("printing of assembly code is enabled; turning on DebugNonSafepoints to gain additional output"); |
e2a449e8cc6f
6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents:
1
diff
changeset
|
632 |
DebugNonSafepoints = true; |
e2a449e8cc6f
6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents:
1
diff
changeset
|
633 |
} |
e2a449e8cc6f
6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents:
1
diff
changeset
|
634 |
} |
1 | 635 |
} |
636 |
||
637 |
||
638 |
void CompilerOracle::parse_compile_only(char * line) { |
|
639 |
int i; |
|
640 |
char name[1024]; |
|
641 |
const char* className = NULL; |
|
642 |
const char* methodName = NULL; |
|
643 |
||
644 |
bool have_colon = (strstr(line, "::") != NULL); |
|
645 |
char method_sep = have_colon ? ':' : '.'; |
|
646 |
||
647 |
if (Verbose) { |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
23185
diff
changeset
|
648 |
tty->print_cr("%s", line); |
1 | 649 |
} |
650 |
||
651 |
ResourceMark rm; |
|
652 |
while (*line != '\0') { |
|
653 |
MethodMatcher::Mode c_match = MethodMatcher::Exact; |
|
654 |
MethodMatcher::Mode m_match = MethodMatcher::Exact; |
|
655 |
||
656 |
for (i = 0; |
|
657 |
i < 1024 && *line != '\0' && *line != method_sep && *line != ',' && !isspace(*line); |
|
658 |
line++, i++) { |
|
659 |
name[i] = *line; |
|
660 |
if (name[i] == '.') name[i] = '/'; // package prefix uses '/' |
|
661 |
} |
|
662 |
||
663 |
if (i > 0) { |
|
664 |
char* newName = NEW_RESOURCE_ARRAY( char, i + 1); |
|
665 |
if (newName == NULL) |
|
666 |
return; |
|
667 |
strncpy(newName, name, i); |
|
668 |
newName[i] = '\0'; |
|
669 |
||
670 |
if (className == NULL) { |
|
671 |
className = newName; |
|
672 |
c_match = MethodMatcher::Prefix; |
|
673 |
} else { |
|
674 |
methodName = newName; |
|
675 |
} |
|
676 |
} |
|
677 |
||
678 |
if (*line == method_sep) { |
|
679 |
if (className == NULL) { |
|
680 |
className = ""; |
|
681 |
c_match = MethodMatcher::Any; |
|
682 |
} else { |
|
683 |
// foo/bar.blah is an exact match on foo/bar, bar.blah is a suffix match on bar |
|
684 |
if (strchr(className, '/') != NULL) { |
|
685 |
c_match = MethodMatcher::Exact; |
|
686 |
} else { |
|
687 |
c_match = MethodMatcher::Suffix; |
|
688 |
} |
|
689 |
} |
|
690 |
} else { |
|
691 |
// got foo or foo/bar |
|
692 |
if (className == NULL) { |
|
693 |
ShouldNotReachHere(); |
|
694 |
} else { |
|
695 |
// got foo or foo/bar |
|
696 |
if (strchr(className, '/') != NULL) { |
|
697 |
c_match = MethodMatcher::Prefix; |
|
698 |
} else if (className[0] == '\0') { |
|
699 |
c_match = MethodMatcher::Any; |
|
700 |
} else { |
|
701 |
c_match = MethodMatcher::Substring; |
|
702 |
} |
|
703 |
} |
|
704 |
} |
|
705 |
||
706 |
// each directive is terminated by , or NUL or . followed by NUL |
|
707 |
if (*line == ',' || *line == '\0' || (line[0] == '.' && line[1] == '\0')) { |
|
708 |
if (methodName == NULL) { |
|
709 |
methodName = ""; |
|
710 |
if (*line != method_sep) { |
|
711 |
m_match = MethodMatcher::Any; |
|
712 |
} |
|
713 |
} |
|
714 |
||
715 |
EXCEPTION_MARK; |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
716 |
Symbol* c_name = SymbolTable::new_symbol(className, CHECK); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
717 |
Symbol* m_name = SymbolTable::new_symbol(methodName, CHECK); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7701
diff
changeset
|
718 |
Symbol* signature = NULL; |
1 | 719 |
|
720 |
add_predicate(CompileOnlyCommand, c_name, c_match, m_name, m_match, signature); |
|
721 |
if (PrintVMOptions) { |
|
722 |
tty->print("CompileOnly: compileonly "); |
|
723 |
lists[CompileOnlyCommand]->print(); |
|
724 |
} |
|
725 |
||
726 |
className = NULL; |
|
727 |
methodName = NULL; |
|
728 |
} |
|
729 |
||
730 |
line = *line == '\0' ? line : line + 1; |
|
731 |
} |
|
732 |
} |