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