Mercurial > hg > graal-compiler
annotate src/share/vm/ci/ciMethod.cpp @ 3897:de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
Reviewed-by: kvn, never
author | twisti |
---|---|
date | Wed, 31 Aug 2011 01:40:45 -0700 |
parents | 2c359f27615c |
children | 5eb9169b1a14 |
rev | line source |
---|---|
0 | 1 /* |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2177
diff
changeset
|
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1251
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1251
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1251
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "ci/ciCallProfile.hpp" | |
27 #include "ci/ciExceptionHandler.hpp" | |
28 #include "ci/ciInstanceKlass.hpp" | |
29 #include "ci/ciMethod.hpp" | |
30 #include "ci/ciMethodBlocks.hpp" | |
31 #include "ci/ciMethodData.hpp" | |
32 #include "ci/ciMethodKlass.hpp" | |
33 #include "ci/ciStreams.hpp" | |
34 #include "ci/ciSymbol.hpp" | |
35 #include "ci/ciUtilities.hpp" | |
36 #include "classfile/systemDictionary.hpp" | |
37 #include "compiler/abstractCompiler.hpp" | |
38 #include "compiler/compilerOracle.hpp" | |
39 #include "compiler/methodLiveness.hpp" | |
40 #include "interpreter/interpreter.hpp" | |
41 #include "interpreter/linkResolver.hpp" | |
42 #include "interpreter/oopMapCache.hpp" | |
43 #include "memory/allocation.inline.hpp" | |
44 #include "memory/resourceArea.hpp" | |
45 #include "oops/generateOopMap.hpp" | |
46 #include "oops/oop.inline.hpp" | |
47 #include "prims/nativeLookup.hpp" | |
48 #include "runtime/deoptimization.hpp" | |
49 #include "utilities/bitMap.inline.hpp" | |
50 #include "utilities/xmlstream.hpp" | |
51 #ifdef COMPILER2 | |
52 #include "ci/bcEscapeAnalyzer.hpp" | |
53 #include "ci/ciTypeFlow.hpp" | |
54 #include "oops/methodOop.hpp" | |
55 #endif | |
56 #ifdef SHARK | |
57 #include "ci/ciTypeFlow.hpp" | |
58 #include "oops/methodOop.hpp" | |
59 #endif | |
0 | 60 |
61 // ciMethod | |
62 // | |
63 // This class represents a methodOop in the HotSpot virtual | |
64 // machine. | |
65 | |
66 | |
67 // ------------------------------------------------------------------ | |
68 // ciMethod::ciMethod | |
69 // | |
70 // Loaded method. | |
71 ciMethod::ciMethod(methodHandle h_m) : ciObject(h_m) { | |
72 assert(h_m() != NULL, "no null method"); | |
73 | |
74 // These fields are always filled in in loaded methods. | |
75 _flags = ciFlags(h_m()->access_flags()); | |
76 | |
77 // Easy to compute, so fill them in now. | |
78 _max_stack = h_m()->max_stack(); | |
79 _max_locals = h_m()->max_locals(); | |
80 _code_size = h_m()->code_size(); | |
81 _intrinsic_id = h_m()->intrinsic_id(); | |
82 _handler_count = h_m()->exception_table()->length() / 4; | |
83 _uses_monitors = h_m()->access_flags().has_monitor_bytecodes(); | |
84 _balanced_monitors = !_uses_monitors || h_m()->access_flags().is_monitor_matching(); | |
1783 | 85 _is_c1_compilable = !h_m()->is_not_c1_compilable(); |
86 _is_c2_compilable = !h_m()->is_not_c2_compilable(); | |
0 | 87 // Lazy fields, filled in on demand. Require allocation. |
88 _code = NULL; | |
89 _exception_handlers = NULL; | |
90 _liveness = NULL; | |
91 _method_blocks = NULL; | |
1692 | 92 #if defined(COMPILER2) || defined(SHARK) |
0 | 93 _flow = NULL; |
1648
8099e71601df
6968368: SIGSEGV in the BCEscapeAnalyzer::copy_dependencies
kvn
parents:
1579
diff
changeset
|
94 _bcea = NULL; |
1692 | 95 #endif // COMPILER2 || SHARK |
0 | 96 |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
710
diff
changeset
|
97 ciEnv *env = CURRENT_ENV; |
1783 | 98 if (env->jvmti_can_hotswap_or_post_breakpoint() && can_be_compiled()) { |
0 | 99 // 6328518 check hotswap conditions under the right lock. |
100 MutexLocker locker(Compile_lock); | |
101 if (Dependencies::check_evol_method(h_m()) != NULL) { | |
1783 | 102 _is_c1_compilable = false; |
103 _is_c2_compilable = false; | |
0 | 104 } |
105 } else { | |
106 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); | |
107 } | |
108 | |
109 if (instanceKlass::cast(h_m()->method_holder())->is_linked()) { | |
110 _can_be_statically_bound = h_m()->can_be_statically_bound(); | |
111 } else { | |
112 // Have to use a conservative value in this case. | |
113 _can_be_statically_bound = false; | |
114 } | |
115 | |
116 // Adjust the definition of this condition to be more useful: | |
117 // %%% take these conditions into account in vtable generation | |
118 if (!_can_be_statically_bound && h_m()->is_private()) | |
119 _can_be_statically_bound = true; | |
120 if (_can_be_statically_bound && h_m()->is_abstract()) | |
121 _can_be_statically_bound = false; | |
122 | |
123 // generating _signature may allow GC and therefore move m. | |
124 // These fields are always filled in. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2007
diff
changeset
|
125 _name = env->get_symbol(h_m()->name()); |
0 | 126 _holder = env->get_object(h_m()->method_holder())->as_instance_klass(); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2007
diff
changeset
|
127 ciSymbol* sig_symbol = env->get_symbol(h_m()->signature()); |
3785
ddd894528dbc
7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents:
2357
diff
changeset
|
128 constantPoolHandle cpool = h_m()->constants(); |
ddd894528dbc
7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents:
2357
diff
changeset
|
129 _signature = new (env->arena()) ciSignature(_holder, cpool, sig_symbol); |
0 | 130 _method_data = NULL; |
131 // Take a snapshot of these values, so they will be commensurate with the MDO. | |
1783 | 132 if (ProfileInterpreter || TieredCompilation) { |
0 | 133 int invcnt = h_m()->interpreter_invocation_count(); |
134 // if the value overflowed report it as max int | |
135 _interpreter_invocation_count = invcnt < 0 ? max_jint : invcnt ; | |
136 _interpreter_throwout_count = h_m()->interpreter_throwout_count(); | |
137 } else { | |
138 _interpreter_invocation_count = 0; | |
139 _interpreter_throwout_count = 0; | |
140 } | |
141 if (_interpreter_invocation_count == 0) | |
142 _interpreter_invocation_count = 1; | |
143 } | |
144 | |
145 | |
146 // ------------------------------------------------------------------ | |
147 // ciMethod::ciMethod | |
148 // | |
149 // Unloaded method. | |
150 ciMethod::ciMethod(ciInstanceKlass* holder, | |
151 ciSymbol* name, | |
152 ciSymbol* signature) : ciObject(ciMethodKlass::make()) { | |
153 // These fields are always filled in. | |
154 _name = name; | |
155 _holder = holder; | |
3785
ddd894528dbc
7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents:
2357
diff
changeset
|
156 _signature = new (CURRENT_ENV->arena()) ciSignature(_holder, constantPoolHandle(), signature); |
0 | 157 _intrinsic_id = vmIntrinsics::_none; |
158 _liveness = NULL; | |
159 _can_be_statically_bound = false; | |
160 _method_blocks = NULL; | |
161 _method_data = NULL; | |
1692 | 162 #if defined(COMPILER2) || defined(SHARK) |
0 | 163 _flow = NULL; |
1648
8099e71601df
6968368: SIGSEGV in the BCEscapeAnalyzer::copy_dependencies
kvn
parents:
1579
diff
changeset
|
164 _bcea = NULL; |
1692 | 165 #endif // COMPILER2 || SHARK |
0 | 166 } |
167 | |
168 | |
169 // ------------------------------------------------------------------ | |
170 // ciMethod::load_code | |
171 // | |
172 // Load the bytecodes and exception handler table for this method. | |
173 void ciMethod::load_code() { | |
174 VM_ENTRY_MARK; | |
175 assert(is_loaded(), "only loaded methods have code"); | |
176 | |
177 methodOop me = get_methodOop(); | |
178 Arena* arena = CURRENT_THREAD_ENV->arena(); | |
179 | |
180 // Load the bytecodes. | |
181 _code = (address)arena->Amalloc(code_size()); | |
182 memcpy(_code, me->code_base(), code_size()); | |
183 | |
184 // Revert any breakpoint bytecodes in ci's copy | |
27
1f530c629c7d
6498878: client compiler crashes on windows when dealing with breakpoint instructions
kvn
parents:
0
diff
changeset
|
185 if (me->number_of_breakpoints() > 0) { |
0 | 186 BreakpointInfo* bp = instanceKlass::cast(me->method_holder())->breakpoints(); |
187 for (; bp != NULL; bp = bp->next()) { | |
188 if (bp->match(me)) { | |
189 code_at_put(bp->bci(), bp->orig_bytecode()); | |
190 } | |
191 } | |
192 } | |
193 | |
194 // And load the exception table. | |
195 typeArrayOop exc_table = me->exception_table(); | |
196 | |
197 // Allocate one extra spot in our list of exceptions. This | |
198 // last entry will be used to represent the possibility that | |
199 // an exception escapes the method. See ciExceptionHandlerStream | |
200 // for details. | |
201 _exception_handlers = | |
202 (ciExceptionHandler**)arena->Amalloc(sizeof(ciExceptionHandler*) | |
203 * (_handler_count + 1)); | |
204 if (_handler_count > 0) { | |
205 for (int i=0; i<_handler_count; i++) { | |
206 int base = i*4; | |
207 _exception_handlers[i] = new (arena) ciExceptionHandler( | |
208 holder(), | |
209 /* start */ exc_table->int_at(base), | |
210 /* limit */ exc_table->int_at(base+1), | |
211 /* goto pc */ exc_table->int_at(base+2), | |
212 /* cp index */ exc_table->int_at(base+3)); | |
213 } | |
214 } | |
215 | |
216 // Put an entry at the end of our list to represent the possibility | |
217 // of exceptional exit. | |
218 _exception_handlers[_handler_count] = | |
219 new (arena) ciExceptionHandler(holder(), 0, code_size(), -1, 0); | |
220 | |
221 if (CIPrintMethodCodes) { | |
222 print_codes(); | |
223 } | |
224 } | |
225 | |
226 | |
227 // ------------------------------------------------------------------ | |
228 // ciMethod::has_linenumber_table | |
229 // | |
230 // length unknown until decompression | |
231 bool ciMethod::has_linenumber_table() const { | |
232 check_is_loaded(); | |
233 VM_ENTRY_MARK; | |
234 return get_methodOop()->has_linenumber_table(); | |
235 } | |
236 | |
237 | |
238 // ------------------------------------------------------------------ | |
239 // ciMethod::compressed_linenumber_table | |
240 u_char* ciMethod::compressed_linenumber_table() const { | |
241 check_is_loaded(); | |
242 VM_ENTRY_MARK; | |
243 return get_methodOop()->compressed_linenumber_table(); | |
244 } | |
245 | |
246 | |
247 // ------------------------------------------------------------------ | |
248 // ciMethod::line_number_from_bci | |
249 int ciMethod::line_number_from_bci(int bci) const { | |
250 check_is_loaded(); | |
251 VM_ENTRY_MARK; | |
252 return get_methodOop()->line_number_from_bci(bci); | |
253 } | |
254 | |
255 | |
256 // ------------------------------------------------------------------ | |
257 // ciMethod::vtable_index | |
258 // | |
259 // Get the position of this method's entry in the vtable, if any. | |
260 int ciMethod::vtable_index() { | |
261 check_is_loaded(); | |
262 assert(holder()->is_linked(), "must be linked"); | |
263 VM_ENTRY_MARK; | |
264 return get_methodOop()->vtable_index(); | |
265 } | |
266 | |
267 | |
1692 | 268 #ifdef SHARK |
269 // ------------------------------------------------------------------ | |
270 // ciMethod::itable_index | |
271 // | |
272 // Get the position of this method's entry in the itable, if any. | |
273 int ciMethod::itable_index() { | |
274 check_is_loaded(); | |
275 assert(holder()->is_linked(), "must be linked"); | |
276 VM_ENTRY_MARK; | |
277 return klassItable::compute_itable_index(get_methodOop()); | |
278 } | |
279 #endif // SHARK | |
280 | |
281 | |
0 | 282 // ------------------------------------------------------------------ |
283 // ciMethod::native_entry | |
284 // | |
285 // Get the address of this method's native code, if any. | |
286 address ciMethod::native_entry() { | |
287 check_is_loaded(); | |
288 assert(flags().is_native(), "must be native method"); | |
289 VM_ENTRY_MARK; | |
290 methodOop method = get_methodOop(); | |
291 address entry = method->native_function(); | |
292 assert(entry != NULL, "must be valid entry point"); | |
293 return entry; | |
294 } | |
295 | |
296 | |
297 // ------------------------------------------------------------------ | |
298 // ciMethod::interpreter_entry | |
299 // | |
300 // Get the entry point for running this method in the interpreter. | |
301 address ciMethod::interpreter_entry() { | |
302 check_is_loaded(); | |
303 VM_ENTRY_MARK; | |
304 methodHandle mh(THREAD, get_methodOop()); | |
305 return Interpreter::entry_for_method(mh); | |
306 } | |
307 | |
308 | |
309 // ------------------------------------------------------------------ | |
310 // ciMethod::uses_balanced_monitors | |
311 // | |
312 // Does this method use monitors in a strict stack-disciplined manner? | |
313 bool ciMethod::has_balanced_monitors() { | |
314 check_is_loaded(); | |
315 if (_balanced_monitors) return true; | |
316 | |
317 // Analyze the method to see if monitors are used properly. | |
318 VM_ENTRY_MARK; | |
319 methodHandle method(THREAD, get_methodOop()); | |
320 assert(method->has_monitor_bytecodes(), "should have checked this"); | |
321 | |
322 // Check to see if a previous compilation computed the | |
323 // monitor-matching analysis. | |
324 if (method->guaranteed_monitor_matching()) { | |
325 _balanced_monitors = true; | |
326 return true; | |
327 } | |
328 | |
329 { | |
330 EXCEPTION_MARK; | |
331 ResourceMark rm(THREAD); | |
332 GeneratePairingInfo gpi(method); | |
333 gpi.compute_map(CATCH); | |
334 if (!gpi.monitor_safe()) { | |
335 return false; | |
336 } | |
337 method->set_guaranteed_monitor_matching(); | |
338 _balanced_monitors = true; | |
339 } | |
340 return true; | |
341 } | |
342 | |
343 | |
344 // ------------------------------------------------------------------ | |
345 // ciMethod::get_flow_analysis | |
346 ciTypeFlow* ciMethod::get_flow_analysis() { | |
1692 | 347 #if defined(COMPILER2) || defined(SHARK) |
0 | 348 if (_flow == NULL) { |
349 ciEnv* env = CURRENT_ENV; | |
350 _flow = new (env->arena()) ciTypeFlow(env, this); | |
351 _flow->do_flow(); | |
352 } | |
353 return _flow; | |
1692 | 354 #else // COMPILER2 || SHARK |
0 | 355 ShouldNotReachHere(); |
356 return NULL; | |
1692 | 357 #endif // COMPILER2 || SHARK |
0 | 358 } |
359 | |
360 | |
361 // ------------------------------------------------------------------ | |
362 // ciMethod::get_osr_flow_analysis | |
363 ciTypeFlow* ciMethod::get_osr_flow_analysis(int osr_bci) { | |
1692 | 364 #if defined(COMPILER2) || defined(SHARK) |
0 | 365 // OSR entry points are always place after a call bytecode of some sort |
366 assert(osr_bci >= 0, "must supply valid OSR entry point"); | |
367 ciEnv* env = CURRENT_ENV; | |
368 ciTypeFlow* flow = new (env->arena()) ciTypeFlow(env, this, osr_bci); | |
369 flow->do_flow(); | |
370 return flow; | |
1692 | 371 #else // COMPILER2 || SHARK |
0 | 372 ShouldNotReachHere(); |
373 return NULL; | |
1692 | 374 #endif // COMPILER2 || SHARK |
0 | 375 } |
376 | |
377 // ------------------------------------------------------------------ | |
991 | 378 // ciMethod::raw_liveness_at_bci |
0 | 379 // |
380 // Which local variables are live at a specific bci? | |
991 | 381 MethodLivenessResult ciMethod::raw_liveness_at_bci(int bci) { |
0 | 382 check_is_loaded(); |
383 if (_liveness == NULL) { | |
384 // Create the liveness analyzer. | |
385 Arena* arena = CURRENT_ENV->arena(); | |
386 _liveness = new (arena) MethodLiveness(arena, this); | |
387 _liveness->compute_liveness(); | |
388 } | |
991 | 389 return _liveness->get_liveness_at(bci); |
390 } | |
391 | |
392 // ------------------------------------------------------------------ | |
393 // ciMethod::liveness_at_bci | |
394 // | |
395 // Which local variables are live at a specific bci? When debugging | |
396 // will return true for all locals in some cases to improve debug | |
397 // information. | |
398 MethodLivenessResult ciMethod::liveness_at_bci(int bci) { | |
399 MethodLivenessResult result = raw_liveness_at_bci(bci); | |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
710
diff
changeset
|
400 if (CURRENT_ENV->jvmti_can_access_local_variables() || DeoptimizeALot || CompileTheWorld) { |
0 | 401 // Keep all locals live for the user's edification and amusement. |
402 result.at_put_range(0, result.size(), true); | |
403 } | |
404 return result; | |
405 } | |
406 | |
407 // ciMethod::live_local_oops_at_bci | |
408 // | |
409 // find all the live oops in the locals array for a particular bci | |
410 // Compute what the interpreter believes by using the interpreter | |
411 // oopmap generator. This is used as a double check during osr to | |
412 // guard against conservative result from MethodLiveness making us | |
413 // think a dead oop is live. MethodLiveness is conservative in the | |
414 // sense that it may consider locals to be live which cannot be live, | |
415 // like in the case where a local could contain an oop or a primitive | |
416 // along different paths. In that case the local must be dead when | |
417 // those paths merge. Since the interpreter's viewpoint is used when | |
418 // gc'ing an interpreter frame we need to use its viewpoint during | |
419 // OSR when loading the locals. | |
420 | |
421 BitMap ciMethod::live_local_oops_at_bci(int bci) { | |
422 VM_ENTRY_MARK; | |
423 InterpreterOopMap mask; | |
424 OopMapCache::compute_one_oop_map(get_methodOop(), bci, &mask); | |
425 int mask_size = max_locals(); | |
426 BitMap result(mask_size); | |
427 result.clear(); | |
428 int i; | |
429 for (i = 0; i < mask_size ; i++ ) { | |
430 if (mask.is_oop(i)) result.set_bit(i); | |
431 } | |
432 return result; | |
433 } | |
434 | |
435 | |
436 #ifdef COMPILER1 | |
437 // ------------------------------------------------------------------ | |
438 // ciMethod::bci_block_start | |
439 // | |
440 // Marks all bcis where a new basic block starts | |
441 const BitMap ciMethod::bci_block_start() { | |
442 check_is_loaded(); | |
443 if (_liveness == NULL) { | |
444 // Create the liveness analyzer. | |
445 Arena* arena = CURRENT_ENV->arena(); | |
446 _liveness = new (arena) MethodLiveness(arena, this); | |
447 _liveness->compute_liveness(); | |
448 } | |
449 | |
450 return _liveness->get_bci_block_start(); | |
451 } | |
452 #endif // COMPILER1 | |
453 | |
454 | |
455 // ------------------------------------------------------------------ | |
456 // ciMethod::call_profile_at_bci | |
457 // | |
458 // Get the ciCallProfile for the invocation of this method. | |
459 // Also reports receiver types for non-call type checks (if TypeProfileCasts). | |
460 ciCallProfile ciMethod::call_profile_at_bci(int bci) { | |
461 ResourceMark rm; | |
462 ciCallProfile result; | |
463 if (method_data() != NULL && method_data()->is_mature()) { | |
464 ciProfileData* data = method_data()->bci_to_data(bci); | |
465 if (data != NULL && data->is_CounterData()) { | |
466 // Every profiled call site has a counter. | |
467 int count = data->as_CounterData()->count(); | |
468 | |
469 if (!data->is_ReceiverTypeData()) { | |
470 result._receiver_count[0] = 0; // that's a definite zero | |
471 } else { // ReceiverTypeData is a subclass of CounterData | |
472 ciReceiverTypeData* call = (ciReceiverTypeData*)data->as_ReceiverTypeData(); | |
473 // In addition, virtual call sites have receiver type information | |
474 int receivers_count_total = 0; | |
475 int morphism = 0; | |
1783 | 476 // Precompute morphism for the possible fixup |
0 | 477 for (uint i = 0; i < call->row_limit(); i++) { |
478 ciKlass* receiver = call->receiver(i); | |
479 if (receiver == NULL) continue; | |
1783 | 480 morphism++; |
481 } | |
482 int epsilon = 0; | |
483 if (TieredCompilation && ProfileInterpreter) { | |
484 // Interpreter and C1 treat final and special invokes differently. | |
485 // C1 will record a type, whereas the interpreter will just | |
486 // increment the count. Detect this case. | |
487 if (morphism == 1 && count > 0) { | |
488 epsilon = count; | |
489 count = 0; | |
490 } | |
491 } | |
492 for (uint i = 0; i < call->row_limit(); i++) { | |
493 ciKlass* receiver = call->receiver(i); | |
494 if (receiver == NULL) continue; | |
495 int rcount = call->receiver_count(i) + epsilon; | |
0 | 496 if (rcount == 0) rcount = 1; // Should be valid value |
497 receivers_count_total += rcount; | |
498 // Add the receiver to result data. | |
499 result.add_receiver(receiver, rcount); | |
500 // If we extend profiling to record methods, | |
501 // we will set result._method also. | |
502 } | |
503 // Determine call site's morphism. | |
1206
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1152
diff
changeset
|
504 // The call site count is 0 with known morphism (onlt 1 or 2 receivers) |
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1152
diff
changeset
|
505 // or < 0 in the case of a type check failured for checkcast, aastore, instanceof. |
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1152
diff
changeset
|
506 // The call site count is > 0 in the case of a polymorphic virtual call. |
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1152
diff
changeset
|
507 if (morphism > 0 && morphism == result._limit) { |
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1152
diff
changeset
|
508 // The morphism <= MorphismLimit. |
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1152
diff
changeset
|
509 if ((morphism < ciCallProfile::MorphismLimit) || |
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1152
diff
changeset
|
510 (morphism == ciCallProfile::MorphismLimit && count == 0)) { |
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1152
diff
changeset
|
511 #ifdef ASSERT |
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1152
diff
changeset
|
512 if (count > 0) { |
1251
576e77447e3c
6923002: assert(false,"this call site should not be polymorphic")
kvn
parents:
1206
diff
changeset
|
513 this->print_short_name(tty); |
576e77447e3c
6923002: assert(false,"this call site should not be polymorphic")
kvn
parents:
1206
diff
changeset
|
514 tty->print_cr(" @ bci:%d", bci); |
1206
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1152
diff
changeset
|
515 this->print_codes(); |
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1152
diff
changeset
|
516 assert(false, "this call site should not be polymorphic"); |
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1152
diff
changeset
|
517 } |
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1152
diff
changeset
|
518 #endif |
0 | 519 result._morphism = morphism; |
520 } | |
521 } | |
522 // Make the count consistent if this is a call profile. If count is | |
523 // zero or less, presume that this is a typecheck profile and | |
524 // do nothing. Otherwise, increase count to be the sum of all | |
525 // receiver's counts. | |
1206
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1152
diff
changeset
|
526 if (count >= 0) { |
87684f1a88b5
6614597: Performance variability in jvm2008 xml.validation
kvn
parents:
1152
diff
changeset
|
527 count += receivers_count_total; |
0 | 528 } |
529 } | |
530 result._count = count; | |
531 } | |
532 } | |
533 return result; | |
534 } | |
535 | |
536 // ------------------------------------------------------------------ | |
537 // Add new receiver and sort data by receiver's profile count. | |
538 void ciCallProfile::add_receiver(ciKlass* receiver, int receiver_count) { | |
539 // Add new receiver and sort data by receiver's counts when we have space | |
540 // for it otherwise replace the less called receiver (less called receiver | |
541 // is placed to the last array element which is not used). | |
542 // First array's element contains most called receiver. | |
543 int i = _limit; | |
544 for (; i > 0 && receiver_count > _receiver_count[i-1]; i--) { | |
545 _receiver[i] = _receiver[i-1]; | |
546 _receiver_count[i] = _receiver_count[i-1]; | |
547 } | |
548 _receiver[i] = receiver; | |
549 _receiver_count[i] = receiver_count; | |
550 if (_limit < MorphismLimit) _limit++; | |
551 } | |
552 | |
553 // ------------------------------------------------------------------ | |
554 // ciMethod::find_monomorphic_target | |
555 // | |
556 // Given a certain calling environment, find the monomorphic target | |
557 // for the call. Return NULL if the call is not monomorphic in | |
558 // its calling environment, or if there are only abstract methods. | |
559 // The returned method is never abstract. | |
560 // Note: If caller uses a non-null result, it must inform dependencies | |
561 // via assert_unique_concrete_method or assert_leaf_type. | |
562 ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller, | |
563 ciInstanceKlass* callee_holder, | |
564 ciInstanceKlass* actual_recv) { | |
565 check_is_loaded(); | |
566 | |
567 if (actual_recv->is_interface()) { | |
568 // %%% We cannot trust interface types, yet. See bug 6312651. | |
569 return NULL; | |
570 } | |
571 | |
572 ciMethod* root_m = resolve_invoke(caller, actual_recv); | |
573 if (root_m == NULL) { | |
574 // Something went wrong looking up the actual receiver method. | |
575 return NULL; | |
576 } | |
577 assert(!root_m->is_abstract(), "resolve_invoke promise"); | |
578 | |
579 // Make certain quick checks even if UseCHA is false. | |
580 | |
581 // Is it private or final? | |
582 if (root_m->can_be_statically_bound()) { | |
583 return root_m; | |
584 } | |
585 | |
586 if (actual_recv->is_leaf_type() && actual_recv == root_m->holder()) { | |
587 // Easy case. There is no other place to put a method, so don't bother | |
588 // to go through the VM_ENTRY_MARK and all the rest. | |
589 return root_m; | |
590 } | |
591 | |
592 // Array methods (clone, hashCode, etc.) are always statically bound. | |
593 // If we were to see an array type here, we'd return root_m. | |
594 // However, this method processes only ciInstanceKlasses. (See 4962591.) | |
595 // The inline_native_clone intrinsic narrows Object to T[] properly, | |
596 // so there is no need to do the same job here. | |
597 | |
598 if (!UseCHA) return NULL; | |
599 | |
600 VM_ENTRY_MARK; | |
601 | |
602 methodHandle target; | |
603 { | |
604 MutexLocker locker(Compile_lock); | |
605 klassOop context = actual_recv->get_klassOop(); | |
606 target = Dependencies::find_unique_concrete_method(context, | |
607 root_m->get_methodOop()); | |
608 // %%% Should upgrade this ciMethod API to look for 1 or 2 concrete methods. | |
609 } | |
610 | |
611 #ifndef PRODUCT | |
612 if (TraceDependencies && target() != NULL && target() != root_m->get_methodOop()) { | |
613 tty->print("found a non-root unique target method"); | |
614 tty->print_cr(" context = %s", instanceKlass::cast(actual_recv->get_klassOop())->external_name()); | |
615 tty->print(" method = "); | |
616 target->print_short_name(tty); | |
617 tty->cr(); | |
618 } | |
619 #endif //PRODUCT | |
620 | |
621 if (target() == NULL) { | |
622 return NULL; | |
623 } | |
624 if (target() == root_m->get_methodOop()) { | |
625 return root_m; | |
626 } | |
627 if (!root_m->is_public() && | |
628 !root_m->is_protected()) { | |
629 // If we are going to reason about inheritance, it's easiest | |
630 // if the method in question is public, protected, or private. | |
631 // If the answer is not root_m, it is conservatively correct | |
632 // to return NULL, even if the CHA encountered irrelevant | |
633 // methods in other packages. | |
634 // %%% TO DO: Work out logic for package-private methods | |
635 // with the same name but different vtable indexes. | |
636 return NULL; | |
637 } | |
638 return CURRENT_THREAD_ENV->get_object(target())->as_method(); | |
639 } | |
640 | |
641 // ------------------------------------------------------------------ | |
642 // ciMethod::resolve_invoke | |
643 // | |
644 // Given a known receiver klass, find the target for the call. | |
645 // Return NULL if the call has no target or the target is abstract. | |
646 ciMethod* ciMethod::resolve_invoke(ciKlass* caller, ciKlass* exact_receiver) { | |
647 check_is_loaded(); | |
648 VM_ENTRY_MARK; | |
649 | |
650 KlassHandle caller_klass (THREAD, caller->get_klassOop()); | |
651 KlassHandle h_recv (THREAD, exact_receiver->get_klassOop()); | |
652 KlassHandle h_resolved (THREAD, holder()->get_klassOop()); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2007
diff
changeset
|
653 Symbol* h_name = name()->get_symbol(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2007
diff
changeset
|
654 Symbol* h_signature = signature()->get_symbol(); |
0 | 655 |
656 methodHandle m; | |
657 // Only do exact lookup if receiver klass has been linked. Otherwise, | |
658 // the vtable has not been setup, and the LinkResolver will fail. | |
659 if (h_recv->oop_is_javaArray() | |
660 || | |
661 instanceKlass::cast(h_recv())->is_linked() && !exact_receiver->is_interface()) { | |
662 if (holder()->is_interface()) { | |
663 m = LinkResolver::resolve_interface_call_or_null(h_recv, h_resolved, h_name, h_signature, caller_klass); | |
664 } else { | |
665 m = LinkResolver::resolve_virtual_call_or_null(h_recv, h_resolved, h_name, h_signature, caller_klass); | |
666 } | |
667 } | |
668 | |
669 if (m.is_null()) { | |
670 // Return NULL only if there was a problem with lookup (uninitialized class, etc.) | |
671 return NULL; | |
672 } | |
673 | |
674 ciMethod* result = this; | |
675 if (m() != get_methodOop()) { | |
676 result = CURRENT_THREAD_ENV->get_object(m())->as_method(); | |
677 } | |
678 | |
679 // Don't return abstract methods because they aren't | |
680 // optimizable or interesting. | |
681 if (result->is_abstract()) { | |
682 return NULL; | |
683 } else { | |
684 return result; | |
685 } | |
686 } | |
687 | |
688 // ------------------------------------------------------------------ | |
689 // ciMethod::resolve_vtable_index | |
690 // | |
691 // Given a known receiver klass, find the vtable index for the call. | |
692 // Return methodOopDesc::invalid_vtable_index if the vtable_index is unknown. | |
693 int ciMethod::resolve_vtable_index(ciKlass* caller, ciKlass* receiver) { | |
694 check_is_loaded(); | |
695 | |
696 int vtable_index = methodOopDesc::invalid_vtable_index; | |
697 // Only do lookup if receiver klass has been linked. Otherwise, | |
698 // the vtable has not been setup, and the LinkResolver will fail. | |
699 if (!receiver->is_interface() | |
700 && (!receiver->is_instance_klass() || | |
701 receiver->as_instance_klass()->is_linked())) { | |
702 VM_ENTRY_MARK; | |
703 | |
704 KlassHandle caller_klass (THREAD, caller->get_klassOop()); | |
705 KlassHandle h_recv (THREAD, receiver->get_klassOop()); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2007
diff
changeset
|
706 Symbol* h_name = name()->get_symbol(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2007
diff
changeset
|
707 Symbol* h_signature = signature()->get_symbol(); |
0 | 708 |
709 vtable_index = LinkResolver::resolve_virtual_vtable_index(h_recv, h_recv, h_name, h_signature, caller_klass); | |
710 if (vtable_index == methodOopDesc::nonvirtual_vtable_index) { | |
711 // A statically bound method. Return "no such index". | |
712 vtable_index = methodOopDesc::invalid_vtable_index; | |
713 } | |
714 } | |
715 | |
716 return vtable_index; | |
717 } | |
718 | |
719 // ------------------------------------------------------------------ | |
720 // ciMethod::interpreter_call_site_count | |
721 int ciMethod::interpreter_call_site_count(int bci) { | |
722 if (method_data() != NULL) { | |
723 ResourceMark rm; | |
724 ciProfileData* data = method_data()->bci_to_data(bci); | |
725 if (data != NULL && data->is_CounterData()) { | |
726 return scale_count(data->as_CounterData()->count()); | |
727 } | |
728 } | |
729 return -1; // unknown | |
730 } | |
731 | |
732 // ------------------------------------------------------------------ | |
733 // Adjust a CounterData count to be commensurate with | |
734 // interpreter_invocation_count. If the MDO exists for | |
735 // only 25% of the time the method exists, then the | |
736 // counts in the MDO should be scaled by 4X, so that | |
737 // they can be usefully and stably compared against the | |
738 // invocation counts in methods. | |
739 int ciMethod::scale_count(int count, float prof_factor) { | |
740 if (count > 0 && method_data() != NULL) { | |
1783 | 741 int counter_life; |
0 | 742 int method_life = interpreter_invocation_count(); |
1783 | 743 if (TieredCompilation) { |
744 // In tiered the MDO's life is measured directly, so just use the snapshotted counters | |
745 counter_life = MAX2(method_data()->invocation_count(), method_data()->backedge_count()); | |
746 } else { | |
747 int current_mileage = method_data()->current_mileage(); | |
748 int creation_mileage = method_data()->creation_mileage(); | |
749 counter_life = current_mileage - creation_mileage; | |
750 } | |
751 | |
0 | 752 // counter_life due to backedge_counter could be > method_life |
753 if (counter_life > method_life) | |
754 counter_life = method_life; | |
755 if (0 < counter_life && counter_life <= method_life) { | |
756 count = (int)((double)count * prof_factor * method_life / counter_life + 0.5); | |
757 count = (count > 0) ? count : 1; | |
758 } | |
759 } | |
760 return count; | |
761 } | |
762 | |
763 // ------------------------------------------------------------------ | |
710 | 764 // invokedynamic support |
1564 | 765 |
766 // ------------------------------------------------------------------ | |
767 // ciMethod::is_method_handle_invoke | |
710 | 768 // |
1662
e0ba4e04c839
6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents:
1648
diff
changeset
|
769 // Return true if the method is an instance of one of the two |
e0ba4e04c839
6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents:
1648
diff
changeset
|
770 // signature-polymorphic MethodHandle methods, invokeExact or invokeGeneric. |
1137
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
991
diff
changeset
|
771 bool ciMethod::is_method_handle_invoke() const { |
1818
c93c652551b5
6986944: JSR 292 assert(caller_nm->is_method_handle_return(caller_frame.pc())) failed: must be MH call site
twisti
parents:
1783
diff
changeset
|
772 if (!is_loaded()) { |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2177
diff
changeset
|
773 bool flag = (holder()->name() == ciSymbol::java_lang_invoke_MethodHandle() && |
1818
c93c652551b5
6986944: JSR 292 assert(caller_nm->is_method_handle_return(caller_frame.pc())) failed: must be MH call site
twisti
parents:
1783
diff
changeset
|
774 methodOopDesc::is_method_handle_invoke_name(name()->sid())); |
c93c652551b5
6986944: JSR 292 assert(caller_nm->is_method_handle_return(caller_frame.pc())) failed: must be MH call site
twisti
parents:
1783
diff
changeset
|
775 return flag; |
c93c652551b5
6986944: JSR 292 assert(caller_nm->is_method_handle_return(caller_frame.pc())) failed: must be MH call site
twisti
parents:
1783
diff
changeset
|
776 } |
1662
e0ba4e04c839
6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents:
1648
diff
changeset
|
777 VM_ENTRY_MARK; |
e0ba4e04c839
6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents:
1648
diff
changeset
|
778 return get_methodOop()->is_method_handle_invoke(); |
710 | 779 } |
780 | |
1564 | 781 // ------------------------------------------------------------------ |
782 // ciMethod::is_method_handle_adapter | |
783 // | |
784 // Return true if the method is a generated MethodHandle adapter. | |
1662
e0ba4e04c839
6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents:
1648
diff
changeset
|
785 // These are built by MethodHandleCompiler. |
1152
cd37471eaecc
6914206: change way of permission checking for generated MethodHandle adapters
twisti
parents:
1137
diff
changeset
|
786 bool ciMethod::is_method_handle_adapter() const { |
1662
e0ba4e04c839
6969574: invokedynamic call sites deoptimize instead of executing
jrose
parents:
1648
diff
changeset
|
787 if (!is_loaded()) return false; |
1152
cd37471eaecc
6914206: change way of permission checking for generated MethodHandle adapters
twisti
parents:
1137
diff
changeset
|
788 VM_ENTRY_MARK; |
cd37471eaecc
6914206: change way of permission checking for generated MethodHandle adapters
twisti
parents:
1137
diff
changeset
|
789 return get_methodOop()->is_method_handle_adapter(); |
cd37471eaecc
6914206: change way of permission checking for generated MethodHandle adapters
twisti
parents:
1137
diff
changeset
|
790 } |
cd37471eaecc
6914206: change way of permission checking for generated MethodHandle adapters
twisti
parents:
1137
diff
changeset
|
791 |
710 | 792 ciInstance* ciMethod::method_handle_type() { |
793 check_is_loaded(); | |
794 VM_ENTRY_MARK; | |
795 oop mtype = get_methodOop()->method_handle_type(); | |
796 return CURRENT_THREAD_ENV->get_object(mtype)->as_instance(); | |
797 } | |
798 | |
799 | |
800 // ------------------------------------------------------------------ | |
2007
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
801 // ciMethod::ensure_method_data |
0 | 802 // |
803 // Generate new methodDataOop objects at compile time. | |
2007
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
804 // Return true if allocation was successful or no MDO is required. |
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
805 bool ciMethod::ensure_method_data(methodHandle h_m) { |
0 | 806 EXCEPTION_CONTEXT; |
2007
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
807 if (is_native() || is_abstract() || h_m()->is_accessor()) return true; |
0 | 808 if (h_m()->method_data() == NULL) { |
809 methodOopDesc::build_interpreter_method_data(h_m, THREAD); | |
810 if (HAS_PENDING_EXCEPTION) { | |
811 CLEAR_PENDING_EXCEPTION; | |
812 } | |
813 } | |
814 if (h_m()->method_data() != NULL) { | |
815 _method_data = CURRENT_ENV->get_object(h_m()->method_data())->as_method_data(); | |
816 _method_data->load_data(); | |
2007
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
817 return true; |
0 | 818 } else { |
819 _method_data = CURRENT_ENV->get_empty_methodData(); | |
2007
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
820 return false; |
0 | 821 } |
822 } | |
823 | |
824 // public, retroactive version | |
2007
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
825 bool ciMethod::ensure_method_data() { |
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
826 bool result = true; |
0 | 827 if (_method_data == NULL || _method_data->is_empty()) { |
828 GUARDED_VM_ENTRY({ | |
2007
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
829 result = ensure_method_data(get_methodOop()); |
0 | 830 }); |
831 } | |
2007
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
832 return result; |
0 | 833 } |
834 | |
835 | |
836 // ------------------------------------------------------------------ | |
837 // ciMethod::method_data | |
838 // | |
839 ciMethodData* ciMethod::method_data() { | |
840 if (_method_data != NULL) { | |
841 return _method_data; | |
842 } | |
843 VM_ENTRY_MARK; | |
844 ciEnv* env = CURRENT_ENV; | |
845 Thread* my_thread = JavaThread::current(); | |
846 methodHandle h_m(my_thread, get_methodOop()); | |
847 | |
848 if (h_m()->method_data() != NULL) { | |
849 _method_data = CURRENT_ENV->get_object(h_m()->method_data())->as_method_data(); | |
850 _method_data->load_data(); | |
851 } else { | |
852 _method_data = CURRENT_ENV->get_empty_methodData(); | |
853 } | |
854 return _method_data; | |
855 | |
856 } | |
857 | |
2007
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
858 // ------------------------------------------------------------------ |
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
859 // ciMethod::method_data_or_null |
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
860 // Returns a pointer to ciMethodData if MDO exists on the VM side, |
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
861 // NULL otherwise. |
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
862 ciMethodData* ciMethod::method_data_or_null() { |
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
863 ciMethodData *md = method_data(); |
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
864 if (md->is_empty()) return NULL; |
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
865 return md; |
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
866 } |
0 | 867 |
868 // ------------------------------------------------------------------ | |
869 // ciMethod::will_link | |
870 // | |
871 // Will this method link in a specific calling context? | |
872 bool ciMethod::will_link(ciKlass* accessing_klass, | |
873 ciKlass* declared_method_holder, | |
874 Bytecodes::Code bc) { | |
875 if (!is_loaded()) { | |
876 // Method lookup failed. | |
877 return false; | |
878 } | |
879 | |
880 // The link checks have been front-loaded into the get_method | |
881 // call. This method (ciMethod::will_link()) will be removed | |
882 // in the future. | |
883 | |
884 return true; | |
885 } | |
886 | |
887 // ------------------------------------------------------------------ | |
888 // ciMethod::should_exclude | |
889 // | |
890 // Should this method be excluded from compilation? | |
891 bool ciMethod::should_exclude() { | |
892 check_is_loaded(); | |
893 VM_ENTRY_MARK; | |
894 methodHandle mh(THREAD, get_methodOop()); | |
895 bool ignore; | |
896 return CompilerOracle::should_exclude(mh, ignore); | |
897 } | |
898 | |
899 // ------------------------------------------------------------------ | |
900 // ciMethod::should_inline | |
901 // | |
902 // Should this method be inlined during compilation? | |
903 bool ciMethod::should_inline() { | |
904 check_is_loaded(); | |
905 VM_ENTRY_MARK; | |
906 methodHandle mh(THREAD, get_methodOop()); | |
907 return CompilerOracle::should_inline(mh); | |
908 } | |
909 | |
910 // ------------------------------------------------------------------ | |
911 // ciMethod::should_not_inline | |
912 // | |
913 // Should this method be disallowed from inlining during compilation? | |
914 bool ciMethod::should_not_inline() { | |
915 check_is_loaded(); | |
916 VM_ENTRY_MARK; | |
917 methodHandle mh(THREAD, get_methodOop()); | |
918 return CompilerOracle::should_not_inline(mh); | |
919 } | |
920 | |
921 // ------------------------------------------------------------------ | |
922 // ciMethod::should_print_assembly | |
923 // | |
924 // Should the compiler print the generated code for this method? | |
925 bool ciMethod::should_print_assembly() { | |
926 check_is_loaded(); | |
927 VM_ENTRY_MARK; | |
928 methodHandle mh(THREAD, get_methodOop()); | |
929 return CompilerOracle::should_print(mh); | |
930 } | |
931 | |
932 // ------------------------------------------------------------------ | |
933 // ciMethod::break_at_execute | |
934 // | |
935 // Should the compiler insert a breakpoint into the generated code | |
936 // method? | |
937 bool ciMethod::break_at_execute() { | |
938 check_is_loaded(); | |
939 VM_ENTRY_MARK; | |
940 methodHandle mh(THREAD, get_methodOop()); | |
941 return CompilerOracle::should_break_at(mh); | |
942 } | |
943 | |
944 // ------------------------------------------------------------------ | |
945 // ciMethod::has_option | |
946 // | |
947 bool ciMethod::has_option(const char* option) { | |
948 check_is_loaded(); | |
949 VM_ENTRY_MARK; | |
950 methodHandle mh(THREAD, get_methodOop()); | |
951 return CompilerOracle::has_option_string(mh, option); | |
952 } | |
953 | |
954 // ------------------------------------------------------------------ | |
955 // ciMethod::can_be_compiled | |
956 // | |
957 // Have previous compilations of this method succeeded? | |
958 bool ciMethod::can_be_compiled() { | |
959 check_is_loaded(); | |
1783 | 960 ciEnv* env = CURRENT_ENV; |
961 if (is_c1_compile(env->comp_level())) { | |
962 return _is_c1_compilable; | |
963 } | |
964 return _is_c2_compilable; | |
0 | 965 } |
966 | |
967 // ------------------------------------------------------------------ | |
968 // ciMethod::set_not_compilable | |
969 // | |
970 // Tell the VM that this method cannot be compiled at all. | |
971 void ciMethod::set_not_compilable() { | |
972 check_is_loaded(); | |
973 VM_ENTRY_MARK; | |
1783 | 974 ciEnv* env = CURRENT_ENV; |
975 if (is_c1_compile(env->comp_level())) { | |
976 _is_c1_compilable = false; | |
977 } else { | |
978 _is_c2_compilable = false; | |
979 } | |
980 get_methodOop()->set_not_compilable(env->comp_level()); | |
0 | 981 } |
982 | |
983 // ------------------------------------------------------------------ | |
984 // ciMethod::can_be_osr_compiled | |
985 // | |
986 // Have previous compilations of this method succeeded? | |
987 // | |
988 // Implementation note: the VM does not currently keep track | |
989 // of failed OSR compilations per bci. The entry_bci parameter | |
990 // is currently unused. | |
991 bool ciMethod::can_be_osr_compiled(int entry_bci) { | |
992 check_is_loaded(); | |
993 VM_ENTRY_MARK; | |
1783 | 994 ciEnv* env = CURRENT_ENV; |
995 return !get_methodOop()->is_not_osr_compilable(env->comp_level()); | |
0 | 996 } |
997 | |
998 // ------------------------------------------------------------------ | |
999 // ciMethod::has_compiled_code | |
1000 bool ciMethod::has_compiled_code() { | |
1001 VM_ENTRY_MARK; | |
1002 return get_methodOop()->code() != NULL; | |
1003 } | |
1004 | |
1783 | 1005 int ciMethod::comp_level() { |
1006 check_is_loaded(); | |
1007 VM_ENTRY_MARK; | |
1008 nmethod* nm = get_methodOop()->code(); | |
1009 if (nm != NULL) return nm->comp_level(); | |
1010 return 0; | |
1011 } | |
1012 | |
3791
2c359f27615c
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
3785
diff
changeset
|
1013 int ciMethod::highest_osr_comp_level() { |
2c359f27615c
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
3785
diff
changeset
|
1014 check_is_loaded(); |
2c359f27615c
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
3785
diff
changeset
|
1015 VM_ENTRY_MARK; |
2c359f27615c
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
3785
diff
changeset
|
1016 return get_methodOop()->highest_osr_comp_level(); |
2c359f27615c
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
3785
diff
changeset
|
1017 } |
2c359f27615c
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
3785
diff
changeset
|
1018 |
0 | 1019 // ------------------------------------------------------------------ |
3897
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1020 // ciMethod::code_size_for_inlining |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1021 // |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1022 // Code size for inlining decisions. |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1023 // |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1024 // Don't fully count method handle adapters against inlining budgets: |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1025 // the metric we use here is the number of call sites in the adapter |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1026 // as they are probably the instructions which generate some code. |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1027 int ciMethod::code_size_for_inlining() { |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1028 check_is_loaded(); |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1029 |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1030 // Method handle adapters |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1031 if (is_method_handle_adapter()) { |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1032 // Count call sites |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1033 int call_site_count = 0; |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1034 ciBytecodeStream iter(this); |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1035 while (iter.next() != ciBytecodeStream::EOBC()) { |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1036 if (Bytecodes::is_invoke(iter.cur_bc())) { |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1037 call_site_count++; |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1038 } |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1039 } |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1040 return call_site_count; |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1041 } |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1042 |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1043 // Normal method |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1044 return code_size(); |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1045 } |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1046 |
de847cac9235
7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents:
3791
diff
changeset
|
1047 // ------------------------------------------------------------------ |
0 | 1048 // ciMethod::instructions_size |
1748 | 1049 // |
1050 // This is a rough metric for "fat" methods, compared before inlining | |
1051 // with InlineSmallCode. The CodeBlob::code_size accessor includes | |
1052 // junk like exception handler, stubs, and constant table, which are | |
1053 // not highly relevant to an inlined method. So we use the more | |
1054 // specific accessor nmethod::insts_size. | |
1783 | 1055 int ciMethod::instructions_size(int comp_level) { |
0 | 1056 GUARDED_VM_ENTRY( |
1057 nmethod* code = get_methodOop()->code(); | |
1783 | 1058 if (code != NULL && (comp_level == CompLevel_any || comp_level == code->comp_level())) { |
1828
3f9a70eb8b1f
6989368: Regression in scimark2.MonteCarlo in jdk7_b112 on Linux
iveresov
parents:
1818
diff
changeset
|
1059 return code->insts_end() - code->verified_entry_point(); |
0 | 1060 } |
1783 | 1061 return 0; |
0 | 1062 ) |
1063 } | |
1064 | |
1065 // ------------------------------------------------------------------ | |
1066 // ciMethod::log_nmethod_identity | |
1067 void ciMethod::log_nmethod_identity(xmlStream* log) { | |
1068 GUARDED_VM_ENTRY( | |
1069 nmethod* code = get_methodOop()->code(); | |
1070 if (code != NULL) { | |
1071 code->log_identity(log); | |
1072 } | |
1073 ) | |
1074 } | |
1075 | |
1076 // ------------------------------------------------------------------ | |
1077 // ciMethod::is_not_reached | |
1078 bool ciMethod::is_not_reached(int bci) { | |
1079 check_is_loaded(); | |
1080 VM_ENTRY_MARK; | |
1081 return Interpreter::is_not_reached( | |
1082 methodHandle(THREAD, get_methodOop()), bci); | |
1083 } | |
1084 | |
1085 // ------------------------------------------------------------------ | |
1086 // ciMethod::was_never_executed | |
1087 bool ciMethod::was_executed_more_than(int times) { | |
1088 VM_ENTRY_MARK; | |
1089 return get_methodOop()->was_executed_more_than(times); | |
1090 } | |
1091 | |
1092 // ------------------------------------------------------------------ | |
1093 // ciMethod::has_unloaded_classes_in_signature | |
1094 bool ciMethod::has_unloaded_classes_in_signature() { | |
1095 VM_ENTRY_MARK; | |
1096 { | |
1097 EXCEPTION_MARK; | |
1098 methodHandle m(THREAD, get_methodOop()); | |
1099 bool has_unloaded = methodOopDesc::has_unloaded_classes_in_signature(m, (JavaThread *)THREAD); | |
1100 if( HAS_PENDING_EXCEPTION ) { | |
1101 CLEAR_PENDING_EXCEPTION; | |
1102 return true; // Declare that we may have unloaded classes | |
1103 } | |
1104 return has_unloaded; | |
1105 } | |
1106 } | |
1107 | |
1108 // ------------------------------------------------------------------ | |
1109 // ciMethod::is_klass_loaded | |
1110 bool ciMethod::is_klass_loaded(int refinfo_index, bool must_be_resolved) const { | |
1111 VM_ENTRY_MARK; | |
1112 return get_methodOop()->is_klass_loaded(refinfo_index, must_be_resolved); | |
1113 } | |
1114 | |
1115 // ------------------------------------------------------------------ | |
1116 // ciMethod::check_call | |
1117 bool ciMethod::check_call(int refinfo_index, bool is_static) const { | |
1118 VM_ENTRY_MARK; | |
1119 { | |
1120 EXCEPTION_MARK; | |
1121 HandleMark hm(THREAD); | |
1122 constantPoolHandle pool (THREAD, get_methodOop()->constants()); | |
1123 methodHandle spec_method; | |
1124 KlassHandle spec_klass; | |
1125 LinkResolver::resolve_method(spec_method, spec_klass, pool, refinfo_index, THREAD); | |
1126 if (HAS_PENDING_EXCEPTION) { | |
1127 CLEAR_PENDING_EXCEPTION; | |
1128 return false; | |
1129 } else { | |
1130 return (spec_method->is_static() == is_static); | |
1131 } | |
1132 } | |
1133 return false; | |
1134 } | |
1135 | |
1136 // ------------------------------------------------------------------ | |
1137 // ciMethod::print_codes | |
1138 // | |
1139 // Print the bytecodes for this method. | |
1140 void ciMethod::print_codes_on(outputStream* st) { | |
1141 check_is_loaded(); | |
1142 GUARDED_VM_ENTRY(get_methodOop()->print_codes_on(st);) | |
1143 } | |
1144 | |
1145 | |
1146 #define FETCH_FLAG_FROM_VM(flag_accessor) { \ | |
1147 check_is_loaded(); \ | |
1148 VM_ENTRY_MARK; \ | |
1149 return get_methodOop()->flag_accessor(); \ | |
1150 } | |
1151 | |
1152 bool ciMethod::is_empty_method() const { FETCH_FLAG_FROM_VM(is_empty_method); } | |
1153 bool ciMethod::is_vanilla_constructor() const { FETCH_FLAG_FROM_VM(is_vanilla_constructor); } | |
1154 bool ciMethod::has_loops () const { FETCH_FLAG_FROM_VM(has_loops); } | |
1155 bool ciMethod::has_jsrs () const { FETCH_FLAG_FROM_VM(has_jsrs); } | |
1156 bool ciMethod::is_accessor () const { FETCH_FLAG_FROM_VM(is_accessor); } | |
1157 bool ciMethod::is_initializer () const { FETCH_FLAG_FROM_VM(is_initializer); } | |
1158 | |
1159 BCEscapeAnalyzer *ciMethod::get_bcea() { | |
1648
8099e71601df
6968368: SIGSEGV in the BCEscapeAnalyzer::copy_dependencies
kvn
parents:
1579
diff
changeset
|
1160 #ifdef COMPILER2 |
0 | 1161 if (_bcea == NULL) { |
1162 _bcea = new (CURRENT_ENV->arena()) BCEscapeAnalyzer(this, NULL); | |
1163 } | |
1164 return _bcea; | |
1648
8099e71601df
6968368: SIGSEGV in the BCEscapeAnalyzer::copy_dependencies
kvn
parents:
1579
diff
changeset
|
1165 #else // COMPILER2 |
8099e71601df
6968368: SIGSEGV in the BCEscapeAnalyzer::copy_dependencies
kvn
parents:
1579
diff
changeset
|
1166 ShouldNotReachHere(); |
8099e71601df
6968368: SIGSEGV in the BCEscapeAnalyzer::copy_dependencies
kvn
parents:
1579
diff
changeset
|
1167 return NULL; |
8099e71601df
6968368: SIGSEGV in the BCEscapeAnalyzer::copy_dependencies
kvn
parents:
1579
diff
changeset
|
1168 #endif // COMPILER2 |
0 | 1169 } |
1170 | |
1171 ciMethodBlocks *ciMethod::get_method_blocks() { | |
1172 Arena *arena = CURRENT_ENV->arena(); | |
1173 if (_method_blocks == NULL) { | |
1174 _method_blocks = new (arena) ciMethodBlocks(arena, this); | |
1175 } | |
1176 return _method_blocks; | |
1177 } | |
1178 | |
1179 #undef FETCH_FLAG_FROM_VM | |
1180 | |
1181 | |
1182 // ------------------------------------------------------------------ | |
1183 // ciMethod::print_codes | |
1184 // | |
1185 // Print a range of the bytecodes for this method. | |
1186 void ciMethod::print_codes_on(int from, int to, outputStream* st) { | |
1187 check_is_loaded(); | |
1188 GUARDED_VM_ENTRY(get_methodOop()->print_codes_on(from, to, st);) | |
1189 } | |
1190 | |
1191 // ------------------------------------------------------------------ | |
1192 // ciMethod::print_name | |
1193 // | |
1194 // Print the name of this method, including signature and some flags. | |
1195 void ciMethod::print_name(outputStream* st) { | |
1196 check_is_loaded(); | |
1197 GUARDED_VM_ENTRY(get_methodOop()->print_name(st);) | |
1198 } | |
1199 | |
1200 // ------------------------------------------------------------------ | |
1201 // ciMethod::print_short_name | |
1202 // | |
1203 // Print the name of this method, without signature. | |
1204 void ciMethod::print_short_name(outputStream* st) { | |
1205 check_is_loaded(); | |
1206 GUARDED_VM_ENTRY(get_methodOop()->print_short_name(st);) | |
1207 } | |
1208 | |
1209 // ------------------------------------------------------------------ | |
1210 // ciMethod::print_impl | |
1211 // | |
1212 // Implementation of the print method. | |
1213 void ciMethod::print_impl(outputStream* st) { | |
1214 ciObject::print_impl(st); | |
1215 st->print(" name="); | |
1216 name()->print_symbol_on(st); | |
1217 st->print(" holder="); | |
1218 holder()->print_name_on(st); | |
1219 st->print(" signature="); | |
1220 signature()->as_symbol()->print_symbol_on(st); | |
1221 if (is_loaded()) { | |
1222 st->print(" loaded=true flags="); | |
1223 flags().print_member_flags(st); | |
1224 } else { | |
1225 st->print(" loaded=false"); | |
1226 } | |
1227 } |