Print this page
rev 6883 : 8057622: java/util/stream/test/org/openjdk/tests/java/util/stream/InfiniteStreamWithLimitOpTest: SEGV inside compiled code (sparc)
Summary: In Parse::array_store_check(), add control edge FROM IfTrue branch of runtime type check of the destination array TO loading _element_klass from destination array.
Reviewed-by: kvn, roland, anoll
Contributed-by: Zoltan Majo <zoltan.majo@oracle.com>
Split |
Split |
Close |
Expand all |
Collapse all |
--- old/hotspot/src/share/vm/opto/parseHelper.cpp
+++ new/hotspot/src/share/vm/opto/parseHelper.cpp
1 1 /*
2 2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 *
23 23 */
24 24
25 25 #include "precompiled.hpp"
26 26 #include "classfile/systemDictionary.hpp"
27 27 #include "compiler/compileLog.hpp"
28 28 #include "oops/objArrayKlass.hpp"
29 29 #include "opto/addnode.hpp"
30 30 #include "opto/memnode.hpp"
31 31 #include "opto/mulnode.hpp"
32 32 #include "opto/parse.hpp"
33 33 #include "opto/rootnode.hpp"
34 34 #include "opto/runtime.hpp"
35 35 #include "runtime/sharedRuntime.hpp"
36 36
37 37 //------------------------------make_dtrace_method_entry_exit ----------------
38 38 // Dtrace -- record entry or exit of a method if compiled with dtrace support
39 39 void GraphKit::make_dtrace_method_entry_exit(ciMethod* method, bool is_entry) {
40 40 const TypeFunc *call_type = OptoRuntime::dtrace_method_entry_exit_Type();
41 41 address call_address = is_entry ? CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry) :
42 42 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit);
43 43 const char *call_name = is_entry ? "dtrace_method_entry" : "dtrace_method_exit";
44 44
45 45 // Get base of thread-local storage area
46 46 Node* thread = _gvn.transform( new (C) ThreadLocalNode() );
47 47
48 48 // Get method
49 49 const TypePtr* method_type = TypeMetadataPtr::make(method);
50 50 Node *method_node = _gvn.transform( ConNode::make(C, method_type) );
51 51
52 52 kill_dead_locals();
53 53
54 54 // For some reason, this call reads only raw memory.
55 55 const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM;
56 56 make_runtime_call(RC_LEAF | RC_NARROW_MEM,
57 57 call_type, call_address,
58 58 call_name, raw_adr_type,
59 59 thread, method_node);
60 60 }
61 61
62 62
63 63 //=============================================================================
64 64 //------------------------------do_checkcast-----------------------------------
65 65 void Parse::do_checkcast() {
66 66 bool will_link;
67 67 ciKlass* klass = iter().get_klass(will_link);
68 68
69 69 Node *obj = peek();
70 70
71 71 // Throw uncommon trap if class is not loaded or the value we are casting
72 72 // _from_ is not loaded, and value is not null. If the value _is_ NULL,
73 73 // then the checkcast does nothing.
74 74 const TypeOopPtr *tp = _gvn.type(obj)->isa_oopptr();
75 75 if (!will_link || (tp && tp->klass() && !tp->klass()->is_loaded())) {
76 76 if (C->log() != NULL) {
77 77 if (!will_link) {
78 78 C->log()->elem("assert_null reason='checkcast' klass='%d'",
79 79 C->log()->identify(klass));
80 80 }
81 81 if (tp && tp->klass() && !tp->klass()->is_loaded()) {
82 82 // %%% Cannot happen?
83 83 C->log()->elem("assert_null reason='checkcast source' klass='%d'",
84 84 C->log()->identify(tp->klass()));
85 85 }
86 86 }
87 87 null_assert(obj);
88 88 assert( stopped() || _gvn.type(peek())->higher_equal(TypePtr::NULL_PTR), "what's left behind is null" );
89 89 if (!stopped()) {
90 90 profile_null_checkcast();
91 91 }
92 92 return;
93 93 }
94 94
95 95 Node *res = gen_checkcast(obj, makecon(TypeKlassPtr::make(klass)) );
96 96
97 97 // Pop from stack AFTER gen_checkcast because it can uncommon trap and
98 98 // the debug info has to be correct.
99 99 pop();
100 100 push(res);
101 101 }
102 102
103 103
104 104 //------------------------------do_instanceof----------------------------------
105 105 void Parse::do_instanceof() {
106 106 if (stopped()) return;
107 107 // We would like to return false if class is not loaded, emitting a
108 108 // dependency, but Java requires instanceof to load its operand.
109 109
110 110 // Throw uncommon trap if class is not loaded
111 111 bool will_link;
112 112 ciKlass* klass = iter().get_klass(will_link);
113 113
114 114 if (!will_link) {
115 115 if (C->log() != NULL) {
116 116 C->log()->elem("assert_null reason='instanceof' klass='%d'",
117 117 C->log()->identify(klass));
118 118 }
119 119 null_assert(peek());
120 120 assert( stopped() || _gvn.type(peek())->higher_equal(TypePtr::NULL_PTR), "what's left behind is null" );
121 121 if (!stopped()) {
122 122 // The object is now known to be null.
123 123 // Shortcut the effect of gen_instanceof and return "false" directly.
124 124 pop(); // pop the null
125 125 push(_gvn.intcon(0)); // push false answer
126 126 }
127 127 return;
128 128 }
129 129
130 130 // Push the bool result back on stack
131 131 Node* res = gen_instanceof(peek(), makecon(TypeKlassPtr::make(klass)), true);
132 132
133 133 // Pop from stack AFTER gen_instanceof because it can uncommon trap.
134 134 pop();
135 135 push(res);
136 136 }
137 137
138 138 //------------------------------array_store_check------------------------------
139 139 // pull array from stack and check that the store is valid
140 140 void Parse::array_store_check() {
141 141
142 142 // Shorthand access to array store elements without popping them.
143 143 Node *obj = peek(0);
144 144 Node *idx = peek(1);
145 145 Node *ary = peek(2);
146 146
147 147 if (_gvn.type(obj) == TypePtr::NULL_PTR) {
148 148 // There's never a type check on null values.
↓ open down ↓ |
148 lines elided |
↑ open up ↑ |
149 149 // This cutout lets us avoid the uncommon_trap(Reason_array_check)
150 150 // below, which turns into a performance liability if the
151 151 // gen_checkcast folds up completely.
152 152 return;
153 153 }
154 154
155 155 // Extract the array klass type
156 156 int klass_offset = oopDesc::klass_offset_in_bytes();
157 157 Node* p = basic_plus_adr( ary, ary, klass_offset );
158 158 // p's type is array-of-OOPS plus klass_offset
159 - Node* array_klass = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeInstPtr::KLASS) );
159 + Node* array_klass = _gvn.transform(LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, TypeInstPtr::KLASS));
160 160 // Get the array klass
161 161 const TypeKlassPtr *tak = _gvn.type(array_klass)->is_klassptr();
162 162
163 - // array_klass's type is generally INexact array-of-oop. Heroically
164 - // cast the array klass to EXACT array and uncommon-trap if the cast
165 - // fails.
163 + // The type of array_klass is usually INexact array-of-oop. Heroically
164 + // cast array_klass to EXACT array and uncommon-trap if the cast fails.
165 + // Make constant out of the inexact array klass, but use it only if the cast
166 + // succeeds.
166 167 bool always_see_exact_class = false;
167 168 if (MonomorphicArrayCheck
168 - && !too_many_traps(Deoptimization::Reason_array_check)) {
169 + && !too_many_traps(Deoptimization::Reason_array_check)
170 + && !tak->klass_is_exact()
171 + && tak != TypeKlassPtr::OBJECT) {
172 + // Regarding the fourth condition in the if-statement from above:
173 + //
174 + // If the compiler has determined that the type of array 'ary' (represented
175 + // by 'array_klass') is java/lang/Object, the compiler must not assume that
176 + // the array 'ary' is monomorphic.
177 + //
178 + // If 'ary' were of type java/lang/Object, this arraystore would have to fail,
179 + // because it is not possible to perform a arraystore into an object that is not
180 + // a "proper" array.
181 + //
182 + // Therefore, let's obtain at runtime the type of 'ary' and check if we can still
183 + // successfully perform the store.
184 + //
185 + // The implementation reasons for the condition are the following:
186 + //
187 + // java/lang/Object is the superclass of all arrays, but it is represented by the VM
188 + // as an InstanceKlass. The checks generated by gen_checkcast() (see below) expect
189 + // 'array_klass' to be ObjArrayKlass, which can result in invalid memory accesses.
190 + //
191 + // See issue JDK-8057622 for details.
192 +
169 193 always_see_exact_class = true;
170 194 // (If no MDO at all, hope for the best, until a trap actually occurs.)
171 - }
172 195
173 - // Is the array klass is exactly its defined type?
174 - if (always_see_exact_class && !tak->klass_is_exact()) {
175 196 // Make a constant out of the inexact array klass
176 197 const TypeKlassPtr *extak = tak->cast_to_exactness(true)->is_klassptr();
177 198 Node* con = makecon(extak);
178 199 Node* cmp = _gvn.transform(new (C) CmpPNode( array_klass, con ));
179 200 Node* bol = _gvn.transform(new (C) BoolNode( cmp, BoolTest::eq ));
180 201 Node* ctrl= control();
181 202 { BuildCutout unless(this, bol, PROB_MAX);
182 203 uncommon_trap(Deoptimization::Reason_array_check,
183 204 Deoptimization::Action_maybe_recompile,
184 205 tak->klass());
185 206 }
186 207 if (stopped()) { // MUST uncommon-trap?
187 208 set_control(ctrl); // Then Don't Do It, just fall into the normal checking
188 209 } else { // Cast array klass to exactness:
189 210 // Use the exact constant value we know it is.
190 211 replace_in_map(array_klass,con);
191 212 CompileLog* log = C->log();
192 213 if (log != NULL) {
193 214 log->elem("cast_up reason='monomorphic_array' from='%d' to='(exact)'",
194 215 log->identify(tak->klass()));
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
195 216 }
196 217 array_klass = con; // Use cast value moving forward
197 218 }
198 219 }
199 220
200 221 // Come here for polymorphic array klasses
201 222
202 223 // Extract the array element class
203 224 int element_klass_offset = in_bytes(ObjArrayKlass::element_klass_offset());
204 225 Node *p2 = basic_plus_adr(array_klass, array_klass, element_klass_offset);
205 - Node *a_e_klass = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p2, tak) );
226 + // We are allowed to use the constant type only if cast succeeded. If always_see_exact_class is true,
227 + // we must set a control edge from the IfTrue node created by the uncommon_trap above to the
228 + // LoadKlassNode.
229 + Node* a_e_klass = _gvn.transform(LoadKlassNode::make(_gvn, always_see_exact_class ? control() : NULL,
230 + immutable_memory(), p2, tak));
206 231
207 232 // Check (the hard way) and throw if not a subklass.
208 233 // Result is ignored, we just need the CFG effects.
209 - gen_checkcast( obj, a_e_klass );
234 + gen_checkcast(obj, a_e_klass);
210 235 }
211 236
212 237
213 238 void Parse::emit_guard_for_new(ciInstanceKlass* klass) {
214 239 // Emit guarded new
215 240 // if (klass->_init_thread != current_thread ||
216 241 // klass->_init_state != being_initialized)
217 242 // uncommon_trap
218 243 Node* cur_thread = _gvn.transform( new (C) ThreadLocalNode() );
219 244 Node* merge = new (C) RegionNode(3);
220 245 _gvn.set_type(merge, Type::CONTROL);
221 246 Node* kls = makecon(TypeKlassPtr::make(klass));
222 247
223 248 Node* init_thread_offset = _gvn.MakeConX(in_bytes(InstanceKlass::init_thread_offset()));
224 249 Node* adr_node = basic_plus_adr(kls, kls, init_thread_offset);
225 250 Node* init_thread = make_load(NULL, adr_node, TypeRawPtr::BOTTOM, T_ADDRESS, MemNode::unordered);
226 251 Node *tst = Bool( CmpP( init_thread, cur_thread), BoolTest::eq);
227 252 IfNode* iff = create_and_map_if(control(), tst, PROB_ALWAYS, COUNT_UNKNOWN);
228 253 set_control(IfTrue(iff));
229 254 merge->set_req(1, IfFalse(iff));
230 255
231 256 Node* init_state_offset = _gvn.MakeConX(in_bytes(InstanceKlass::init_state_offset()));
232 257 adr_node = basic_plus_adr(kls, kls, init_state_offset);
233 258 // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler
234 259 // can generate code to load it as unsigned byte.
235 260 Node* init_state = make_load(NULL, adr_node, TypeInt::UBYTE, T_BOOLEAN, MemNode::unordered);
236 261 Node* being_init = _gvn.intcon(InstanceKlass::being_initialized);
237 262 tst = Bool( CmpI( init_state, being_init), BoolTest::eq);
238 263 iff = create_and_map_if(control(), tst, PROB_ALWAYS, COUNT_UNKNOWN);
239 264 set_control(IfTrue(iff));
240 265 merge->set_req(2, IfFalse(iff));
241 266
242 267 PreserveJVMState pjvms(this);
243 268 record_for_igvn(merge);
244 269 set_control(merge);
245 270
246 271 uncommon_trap(Deoptimization::Reason_uninitialized,
247 272 Deoptimization::Action_reinterpret,
248 273 klass);
249 274 }
250 275
251 276
252 277 //------------------------------do_new-----------------------------------------
253 278 void Parse::do_new() {
254 279 kill_dead_locals();
255 280
256 281 bool will_link;
257 282 ciInstanceKlass* klass = iter().get_klass(will_link)->as_instance_klass();
258 283 assert(will_link, "_new: typeflow responsibility");
259 284
260 285 // Should initialize, or throw an InstantiationError?
261 286 if (!klass->is_initialized() && !klass->is_being_initialized() ||
262 287 klass->is_abstract() || klass->is_interface() ||
263 288 klass->name() == ciSymbol::java_lang_Class() ||
264 289 iter().is_unresolved_klass()) {
265 290 uncommon_trap(Deoptimization::Reason_uninitialized,
266 291 Deoptimization::Action_reinterpret,
267 292 klass);
268 293 return;
269 294 }
270 295 if (klass->is_being_initialized()) {
271 296 emit_guard_for_new(klass);
272 297 }
273 298
274 299 Node* kls = makecon(TypeKlassPtr::make(klass));
275 300 Node* obj = new_instance(kls);
276 301
277 302 // Push resultant oop onto stack
278 303 push(obj);
279 304
280 305 // Keep track of whether opportunities exist for StringBuilder
281 306 // optimizations.
282 307 if (OptimizeStringConcat &&
283 308 (klass == C->env()->StringBuilder_klass() ||
284 309 klass == C->env()->StringBuffer_klass())) {
285 310 C->set_has_stringbuilder(true);
286 311 }
287 312
288 313 // Keep track of boxed values for EliminateAutoBox optimizations.
289 314 if (C->eliminate_boxing() && klass->is_box_klass()) {
290 315 C->set_has_boxed_value(true);
291 316 }
292 317 }
293 318
294 319 #ifndef PRODUCT
295 320 //------------------------------dump_map_adr_mem-------------------------------
296 321 // Debug dump of the mapping from address types to MergeMemNode indices.
297 322 void Parse::dump_map_adr_mem() const {
298 323 tty->print_cr("--- Mapping from address types to memory Nodes ---");
299 324 MergeMemNode *mem = map() == NULL ? NULL : (map()->memory()->is_MergeMem() ?
300 325 map()->memory()->as_MergeMem() : NULL);
301 326 for (uint i = 0; i < (uint)C->num_alias_types(); i++) {
302 327 C->alias_type(i)->print_on(tty);
303 328 tty->print("\t");
304 329 // Node mapping, if any
305 330 if (mem && i < mem->req() && mem->in(i) && mem->in(i) != mem->empty_memory()) {
306 331 mem->in(i)->dump();
307 332 } else {
308 333 tty->cr();
309 334 }
310 335 }
311 336 }
312 337
313 338 #endif
314 339
315 340
316 341 //=============================================================================
317 342 //
318 343 // parser methods for profiling
319 344
320 345
321 346 //----------------------test_counter_against_threshold ------------------------
322 347 void Parse::test_counter_against_threshold(Node* cnt, int limit) {
323 348 // Test the counter against the limit and uncommon trap if greater.
324 349
325 350 // This code is largely copied from the range check code in
326 351 // array_addressing()
327 352
328 353 // Test invocation count vs threshold
329 354 Node *threshold = makecon(TypeInt::make(limit));
330 355 Node *chk = _gvn.transform( new (C) CmpUNode( cnt, threshold) );
331 356 BoolTest::mask btest = BoolTest::lt;
332 357 Node *tst = _gvn.transform( new (C) BoolNode( chk, btest) );
333 358 // Branch to failure if threshold exceeded
334 359 { BuildCutout unless(this, tst, PROB_ALWAYS);
335 360 uncommon_trap(Deoptimization::Reason_age,
336 361 Deoptimization::Action_maybe_recompile);
337 362 }
338 363 }
339 364
340 365 //----------------------increment_and_test_invocation_counter-------------------
341 366 void Parse::increment_and_test_invocation_counter(int limit) {
342 367 if (!count_invocations()) return;
343 368
344 369 // Get the Method* node.
345 370 ciMethod* m = method();
346 371 MethodCounters* counters_adr = m->ensure_method_counters();
347 372 if (counters_adr == NULL) {
348 373 C->record_failure("method counters allocation failed");
349 374 return;
350 375 }
351 376
352 377 Node* ctrl = control();
353 378 const TypePtr* adr_type = TypeRawPtr::make((address) counters_adr);
354 379 Node *counters_node = makecon(adr_type);
355 380 Node* adr_iic_node = basic_plus_adr(counters_node, counters_node,
356 381 MethodCounters::interpreter_invocation_counter_offset_in_bytes());
357 382 Node* cnt = make_load(ctrl, adr_iic_node, TypeInt::INT, T_INT, adr_type, MemNode::unordered);
358 383
359 384 test_counter_against_threshold(cnt, limit);
360 385
361 386 // Add one to the counter and store
362 387 Node* incr = _gvn.transform(new (C) AddINode(cnt, _gvn.intcon(1)));
363 388 store_to_memory(ctrl, adr_iic_node, incr, T_INT, adr_type, MemNode::unordered);
364 389 }
365 390
366 391 //----------------------------method_data_addressing---------------------------
367 392 Node* Parse::method_data_addressing(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, Node* idx, uint stride) {
368 393 // Get offset within MethodData* of the data array
369 394 ByteSize data_offset = MethodData::data_offset();
370 395
371 396 // Get cell offset of the ProfileData within data array
372 397 int cell_offset = md->dp_to_di(data->dp());
373 398
374 399 // Add in counter_offset, the # of bytes into the ProfileData of counter or flag
375 400 int offset = in_bytes(data_offset) + cell_offset + in_bytes(counter_offset);
376 401
377 402 const TypePtr* adr_type = TypeMetadataPtr::make(md);
378 403 Node* mdo = makecon(adr_type);
379 404 Node* ptr = basic_plus_adr(mdo, mdo, offset);
380 405
381 406 if (stride != 0) {
382 407 Node* str = _gvn.MakeConX(stride);
383 408 Node* scale = _gvn.transform( new (C) MulXNode( idx, str ) );
384 409 ptr = _gvn.transform( new (C) AddPNode( mdo, ptr, scale ) );
385 410 }
386 411
387 412 return ptr;
388 413 }
389 414
390 415 //--------------------------increment_md_counter_at----------------------------
391 416 void Parse::increment_md_counter_at(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, Node* idx, uint stride) {
392 417 Node* adr_node = method_data_addressing(md, data, counter_offset, idx, stride);
393 418
394 419 const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr();
395 420 Node* cnt = make_load(NULL, adr_node, TypeInt::INT, T_INT, adr_type, MemNode::unordered);
396 421 Node* incr = _gvn.transform(new (C) AddINode(cnt, _gvn.intcon(DataLayout::counter_increment)));
397 422 store_to_memory(NULL, adr_node, incr, T_INT, adr_type, MemNode::unordered);
398 423 }
399 424
400 425 //--------------------------test_for_osr_md_counter_at-------------------------
401 426 void Parse::test_for_osr_md_counter_at(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, int limit) {
402 427 Node* adr_node = method_data_addressing(md, data, counter_offset);
403 428
404 429 const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr();
405 430 Node* cnt = make_load(NULL, adr_node, TypeInt::INT, T_INT, adr_type, MemNode::unordered);
406 431
407 432 test_counter_against_threshold(cnt, limit);
408 433 }
409 434
410 435 //-------------------------------set_md_flag_at--------------------------------
411 436 void Parse::set_md_flag_at(ciMethodData* md, ciProfileData* data, int flag_constant) {
412 437 Node* adr_node = method_data_addressing(md, data, DataLayout::flags_offset());
413 438
414 439 const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr();
415 440 Node* flags = make_load(NULL, adr_node, TypeInt::BYTE, T_BYTE, adr_type, MemNode::unordered);
416 441 Node* incr = _gvn.transform(new (C) OrINode(flags, _gvn.intcon(flag_constant)));
417 442 store_to_memory(NULL, adr_node, incr, T_BYTE, adr_type, MemNode::unordered);
418 443 }
419 444
420 445 //----------------------------profile_taken_branch-----------------------------
421 446 void Parse::profile_taken_branch(int target_bci, bool force_update) {
422 447 // This is a potential osr_site if we have a backedge.
423 448 int cur_bci = bci();
424 449 bool osr_site =
425 450 (target_bci <= cur_bci) && count_invocations() && UseOnStackReplacement;
426 451
427 452 // If we are going to OSR, restart at the target bytecode.
428 453 set_bci(target_bci);
429 454
430 455 // To do: factor out the the limit calculations below. These duplicate
431 456 // the similar limit calculations in the interpreter.
432 457
433 458 if (method_data_update() || force_update) {
434 459 ciMethodData* md = method()->method_data();
435 460 assert(md != NULL, "expected valid ciMethodData");
436 461 ciProfileData* data = md->bci_to_data(cur_bci);
437 462 assert(data->is_JumpData(), "need JumpData for taken branch");
438 463 increment_md_counter_at(md, data, JumpData::taken_offset());
439 464 }
440 465
441 466 // In the new tiered system this is all we need to do. In the old
442 467 // (c2 based) tiered sytem we must do the code below.
443 468 #ifndef TIERED
444 469 if (method_data_update()) {
445 470 ciMethodData* md = method()->method_data();
446 471 if (osr_site) {
447 472 ciProfileData* data = md->bci_to_data(cur_bci);
448 473 int limit = (CompileThreshold
449 474 * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;
450 475 test_for_osr_md_counter_at(md, data, JumpData::taken_offset(), limit);
451 476 }
452 477 } else {
453 478 // With method data update off, use the invocation counter to trigger an
454 479 // OSR compilation, as done in the interpreter.
455 480 if (osr_site) {
456 481 int limit = (CompileThreshold * OnStackReplacePercentage) / 100;
457 482 increment_and_test_invocation_counter(limit);
458 483 }
459 484 }
460 485 #endif // TIERED
461 486
462 487 // Restore the original bytecode.
463 488 set_bci(cur_bci);
464 489 }
465 490
466 491 //--------------------------profile_not_taken_branch---------------------------
467 492 void Parse::profile_not_taken_branch(bool force_update) {
468 493
469 494 if (method_data_update() || force_update) {
470 495 ciMethodData* md = method()->method_data();
471 496 assert(md != NULL, "expected valid ciMethodData");
472 497 ciProfileData* data = md->bci_to_data(bci());
473 498 assert(data->is_BranchData(), "need BranchData for not taken branch");
474 499 increment_md_counter_at(md, data, BranchData::not_taken_offset());
475 500 }
476 501
477 502 }
478 503
479 504 //---------------------------------profile_call--------------------------------
480 505 void Parse::profile_call(Node* receiver) {
481 506 if (!method_data_update()) return;
482 507
483 508 switch (bc()) {
484 509 case Bytecodes::_invokevirtual:
485 510 case Bytecodes::_invokeinterface:
486 511 profile_receiver_type(receiver);
487 512 break;
488 513 case Bytecodes::_invokestatic:
489 514 case Bytecodes::_invokedynamic:
490 515 case Bytecodes::_invokespecial:
491 516 profile_generic_call();
492 517 break;
493 518 default: fatal("unexpected call bytecode");
494 519 }
495 520 }
496 521
497 522 //------------------------------profile_generic_call---------------------------
498 523 void Parse::profile_generic_call() {
499 524 assert(method_data_update(), "must be generating profile code");
500 525
501 526 ciMethodData* md = method()->method_data();
502 527 assert(md != NULL, "expected valid ciMethodData");
503 528 ciProfileData* data = md->bci_to_data(bci());
504 529 assert(data->is_CounterData(), "need CounterData for not taken branch");
505 530 increment_md_counter_at(md, data, CounterData::count_offset());
506 531 }
507 532
508 533 //-----------------------------profile_receiver_type---------------------------
509 534 void Parse::profile_receiver_type(Node* receiver) {
510 535 assert(method_data_update(), "must be generating profile code");
511 536
512 537 ciMethodData* md = method()->method_data();
513 538 assert(md != NULL, "expected valid ciMethodData");
514 539 ciProfileData* data = md->bci_to_data(bci());
515 540 assert(data->is_ReceiverTypeData(), "need ReceiverTypeData here");
516 541
517 542 // Skip if we aren't tracking receivers
518 543 if (TypeProfileWidth < 1) {
519 544 increment_md_counter_at(md, data, CounterData::count_offset());
520 545 return;
521 546 }
522 547 ciReceiverTypeData* rdata = (ciReceiverTypeData*)data->as_ReceiverTypeData();
523 548
524 549 Node* method_data = method_data_addressing(md, rdata, in_ByteSize(0));
525 550
526 551 // Using an adr_type of TypePtr::BOTTOM to work around anti-dep problems.
527 552 // A better solution might be to use TypeRawPtr::BOTTOM with RC_NARROW_MEM.
528 553 make_runtime_call(RC_LEAF, OptoRuntime::profile_receiver_type_Type(),
529 554 CAST_FROM_FN_PTR(address,
530 555 OptoRuntime::profile_receiver_type_C),
531 556 "profile_receiver_type_C",
532 557 TypePtr::BOTTOM,
533 558 method_data, receiver);
534 559 }
535 560
536 561 //---------------------------------profile_ret---------------------------------
537 562 void Parse::profile_ret(int target_bci) {
538 563 if (!method_data_update()) return;
539 564
540 565 // Skip if we aren't tracking ret targets
541 566 if (TypeProfileWidth < 1) return;
542 567
543 568 ciMethodData* md = method()->method_data();
544 569 assert(md != NULL, "expected valid ciMethodData");
545 570 ciProfileData* data = md->bci_to_data(bci());
546 571 assert(data->is_RetData(), "need RetData for ret");
547 572 ciRetData* ret_data = (ciRetData*)data->as_RetData();
548 573
549 574 // Look for the target_bci is already in the table
550 575 uint row;
551 576 bool table_full = true;
552 577 for (row = 0; row < ret_data->row_limit(); row++) {
553 578 int key = ret_data->bci(row);
554 579 table_full &= (key != RetData::no_bci);
555 580 if (key == target_bci) break;
556 581 }
557 582
558 583 if (row >= ret_data->row_limit()) {
559 584 // The target_bci was not found in the table.
560 585 if (!table_full) {
561 586 // XXX: Make slow call to update RetData
562 587 }
563 588 return;
564 589 }
565 590
566 591 // the target_bci is already in the table
567 592 increment_md_counter_at(md, data, RetData::bci_count_offset(row));
568 593 }
569 594
570 595 //--------------------------profile_null_checkcast----------------------------
571 596 void Parse::profile_null_checkcast() {
572 597 // Set the null-seen flag, done in conjunction with the usual null check. We
573 598 // never unset the flag, so this is a one-way switch.
574 599 if (!method_data_update()) return;
575 600
576 601 ciMethodData* md = method()->method_data();
577 602 assert(md != NULL, "expected valid ciMethodData");
578 603 ciProfileData* data = md->bci_to_data(bci());
579 604 assert(data->is_BitData(), "need BitData for checkcast");
580 605 set_md_flag_at(md, data, BitData::null_seen_byte_constant());
581 606 }
582 607
583 608 //-----------------------------profile_switch_case-----------------------------
584 609 void Parse::profile_switch_case(int table_index) {
585 610 if (!method_data_update()) return;
586 611
587 612 ciMethodData* md = method()->method_data();
588 613 assert(md != NULL, "expected valid ciMethodData");
589 614
590 615 ciProfileData* data = md->bci_to_data(bci());
591 616 assert(data->is_MultiBranchData(), "need MultiBranchData for switch case");
592 617 if (table_index >= 0) {
593 618 increment_md_counter_at(md, data, MultiBranchData::case_count_offset(table_index));
594 619 } else {
595 620 increment_md_counter_at(md, data, MultiBranchData::default_count_offset());
596 621 }
597 622 }
↓ open down ↓ |
378 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX