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