Print this page
rev 1024 : imported patch indy-cleanup-6893081.patch
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/vm/opto/runtime.cpp
+++ new/src/share/vm/opto/runtime.cpp
1 1 /*
2 - * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
2 + * Copyright 1998-2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 21 * have any questions.
22 22 *
23 23 */
24 24
25 25 #include "incls/_precompiled.incl"
26 26 #include "incls/_runtime.cpp.incl"
27 27
28 28
29 29 // For debugging purposes:
30 30 // To force FullGCALot inside a runtime function, add the following two lines
31 31 //
32 32 // Universe::release_fullgc_alot_dummy();
33 33 // MarkSweep::invoke(0, "Debugging");
34 34 //
35 35 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
36 36
37 37
38 38
39 39
40 40 // Compiled code entry points
41 41 address OptoRuntime::_new_instance_Java = NULL;
42 42 address OptoRuntime::_new_array_Java = NULL;
43 43 address OptoRuntime::_multianewarray2_Java = NULL;
44 44 address OptoRuntime::_multianewarray3_Java = NULL;
45 45 address OptoRuntime::_multianewarray4_Java = NULL;
46 46 address OptoRuntime::_multianewarray5_Java = NULL;
47 47 address OptoRuntime::_g1_wb_pre_Java = NULL;
48 48 address OptoRuntime::_g1_wb_post_Java = NULL;
49 49 address OptoRuntime::_vtable_must_compile_Java = NULL;
50 50 address OptoRuntime::_complete_monitor_locking_Java = NULL;
51 51 address OptoRuntime::_rethrow_Java = NULL;
52 52
53 53 address OptoRuntime::_slow_arraycopy_Java = NULL;
54 54 address OptoRuntime::_register_finalizer_Java = NULL;
55 55
56 56 # ifdef ENABLE_ZAP_DEAD_LOCALS
57 57 address OptoRuntime::_zap_dead_Java_locals_Java = NULL;
58 58 address OptoRuntime::_zap_dead_native_locals_Java = NULL;
59 59 # endif
60 60
61 61
62 62 // This should be called in an assertion at the start of OptoRuntime routines
63 63 // which are entered from compiled code (all of them)
64 64 #ifndef PRODUCT
65 65 static bool check_compiled_frame(JavaThread* thread) {
66 66 assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
67 67 #ifdef ASSERT
68 68 RegisterMap map(thread, false);
69 69 frame caller = thread->last_frame().sender(&map);
70 70 assert(caller.is_compiled_frame(), "not being called from compiled like code");
71 71 #endif /* ASSERT */
72 72 return true;
73 73 }
74 74 #endif
75 75
76 76
77 77 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, save_arg_regs, return_pc) \
78 78 var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, save_arg_regs, return_pc)
79 79
80 80 void OptoRuntime::generate(ciEnv* env) {
81 81
82 82 generate_exception_blob();
83 83
84 84 // Note: tls: Means fetching the return oop out of the thread-local storage
85 85 //
86 86 // variable/name type-function-gen , runtime method ,fncy_jp, tls,save_args,retpc
87 87 // -------------------------------------------------------------------------------------------------------------------------------
88 88 gen(env, _new_instance_Java , new_instance_Type , new_instance_C , 0 , true , false, false);
89 89 gen(env, _new_array_Java , new_array_Type , new_array_C , 0 , true , false, false);
90 90 gen(env, _multianewarray2_Java , multianewarray2_Type , multianewarray2_C , 0 , true , false, false);
91 91 gen(env, _multianewarray3_Java , multianewarray3_Type , multianewarray3_C , 0 , true , false, false);
92 92 gen(env, _multianewarray4_Java , multianewarray4_Type , multianewarray4_C , 0 , true , false, false);
93 93 gen(env, _multianewarray5_Java , multianewarray5_Type , multianewarray5_C , 0 , true , false, false);
94 94 gen(env, _g1_wb_pre_Java , g1_wb_pre_Type , SharedRuntime::g1_wb_pre , 0 , false, false, false);
95 95 gen(env, _g1_wb_post_Java , g1_wb_post_Type , SharedRuntime::g1_wb_post , 0 , false, false, false);
96 96 gen(env, _complete_monitor_locking_Java , complete_monitor_enter_Type , SharedRuntime::complete_monitor_locking_C , 0 , false, false, false);
97 97 gen(env, _rethrow_Java , rethrow_Type , rethrow_C , 2 , true , false, true );
98 98
99 99 gen(env, _slow_arraycopy_Java , slow_arraycopy_Type , SharedRuntime::slow_arraycopy_C , 0 , false, false, false);
100 100 gen(env, _register_finalizer_Java , register_finalizer_Type , register_finalizer , 0 , false, false, false);
101 101
102 102 # ifdef ENABLE_ZAP_DEAD_LOCALS
103 103 gen(env, _zap_dead_Java_locals_Java , zap_dead_locals_Type , zap_dead_Java_locals_C , 0 , false, true , false );
104 104 gen(env, _zap_dead_native_locals_Java , zap_dead_locals_Type , zap_dead_native_locals_C , 0 , false, true , false );
105 105 # endif
106 106
107 107 }
108 108
109 109 #undef gen
110 110
111 111
112 112 // Helper method to do generation of RunTimeStub's
113 113 address OptoRuntime::generate_stub( ciEnv* env,
114 114 TypeFunc_generator gen, address C_function,
115 115 const char *name, int is_fancy_jump,
116 116 bool pass_tls,
117 117 bool save_argument_registers,
118 118 bool return_pc ) {
119 119 ResourceMark rm;
120 120 Compile C( env, gen, C_function, name, is_fancy_jump, pass_tls, save_argument_registers, return_pc );
121 121 return C.stub_entry_point();
122 122 }
123 123
124 124 const char* OptoRuntime::stub_name(address entry) {
125 125 #ifndef PRODUCT
126 126 CodeBlob* cb = CodeCache::find_blob(entry);
127 127 RuntimeStub* rs =(RuntimeStub *)cb;
128 128 assert(rs != NULL && rs->is_runtime_stub(), "not a runtime stub");
129 129 return rs->name();
130 130 #else
131 131 // Fast implementation for product mode (maybe it should be inlined too)
132 132 return "runtime stub";
133 133 #endif
134 134 }
135 135
136 136
137 137 //=============================================================================
138 138 // Opto compiler runtime routines
139 139 //=============================================================================
140 140
141 141
142 142 //=============================allocation======================================
143 143 // We failed the fast-path allocation. Now we need to do a scavenge or GC
144 144 // and try allocation again.
145 145
146 146 void OptoRuntime::do_eager_card_mark(JavaThread* thread) {
147 147 // After any safepoint, just before going back to compiled code,
148 148 // we perform a card mark. This lets the compiled code omit
149 149 // card marks for initialization of new objects.
150 150 // Keep this code consistent with GraphKit::store_barrier.
151 151
152 152 oop new_obj = thread->vm_result();
153 153 if (new_obj == NULL) return;
154 154
155 155 assert(Universe::heap()->can_elide_tlab_store_barriers(),
156 156 "compiler must check this first");
157 157 new_obj = Universe::heap()->new_store_barrier(new_obj);
158 158 thread->set_vm_result(new_obj);
159 159 }
160 160
161 161 // object allocation
162 162 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(klassOopDesc* klass, JavaThread* thread))
163 163 JRT_BLOCK;
164 164 #ifndef PRODUCT
165 165 SharedRuntime::_new_instance_ctr++; // new instance requires GC
166 166 #endif
167 167 assert(check_compiled_frame(thread), "incorrect caller");
168 168
169 169 // These checks are cheap to make and support reflective allocation.
170 170 int lh = Klass::cast(klass)->layout_helper();
171 171 if (Klass::layout_helper_needs_slow_path(lh)
172 172 || !instanceKlass::cast(klass)->is_initialized()) {
173 173 KlassHandle kh(THREAD, klass);
174 174 kh->check_valid_for_instantiation(false, THREAD);
175 175 if (!HAS_PENDING_EXCEPTION) {
176 176 instanceKlass::cast(kh())->initialize(THREAD);
177 177 }
178 178 if (!HAS_PENDING_EXCEPTION) {
179 179 klass = kh();
180 180 } else {
181 181 klass = NULL;
182 182 }
183 183 }
184 184
185 185 if (klass != NULL) {
186 186 // Scavenge and allocate an instance.
187 187 oop result = instanceKlass::cast(klass)->allocate_instance(THREAD);
188 188 thread->set_vm_result(result);
189 189
190 190 // Pass oops back through thread local storage. Our apparent type to Java
191 191 // is that we return an oop, but we can block on exit from this routine and
192 192 // a GC can trash the oop in C's return register. The generated stub will
193 193 // fetch the oop from TLS after any possible GC.
194 194 }
195 195
196 196 deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
197 197 JRT_BLOCK_END;
198 198
199 199 if (GraphKit::use_ReduceInitialCardMarks()) {
200 200 // do them now so we don't have to do them on the fast path
201 201 do_eager_card_mark(thread);
202 202 }
203 203 JRT_END
204 204
205 205
206 206 // array allocation
207 207 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(klassOopDesc* array_type, int len, JavaThread *thread))
208 208 JRT_BLOCK;
209 209 #ifndef PRODUCT
210 210 SharedRuntime::_new_array_ctr++; // new array requires GC
211 211 #endif
212 212 assert(check_compiled_frame(thread), "incorrect caller");
213 213
214 214 // Scavenge and allocate an instance.
215 215 oop result;
216 216
217 217 if (Klass::cast(array_type)->oop_is_typeArray()) {
218 218 // The oopFactory likes to work with the element type.
219 219 // (We could bypass the oopFactory, since it doesn't add much value.)
220 220 BasicType elem_type = typeArrayKlass::cast(array_type)->element_type();
221 221 result = oopFactory::new_typeArray(elem_type, len, THREAD);
222 222 } else {
223 223 // Although the oopFactory likes to work with the elem_type,
224 224 // the compiler prefers the array_type, since it must already have
225 225 // that latter value in hand for the fast path.
226 226 klassOopDesc* elem_type = objArrayKlass::cast(array_type)->element_klass();
227 227 result = oopFactory::new_objArray(elem_type, len, THREAD);
228 228 }
229 229
230 230 // Pass oops back through thread local storage. Our apparent type to Java
231 231 // is that we return an oop, but we can block on exit from this routine and
232 232 // a GC can trash the oop in C's return register. The generated stub will
233 233 // fetch the oop from TLS after any possible GC.
234 234 deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
235 235 thread->set_vm_result(result);
236 236 JRT_BLOCK_END;
237 237
238 238 if (GraphKit::use_ReduceInitialCardMarks()) {
239 239 // do them now so we don't have to do them on the fast path
240 240 do_eager_card_mark(thread);
241 241 }
242 242 JRT_END
243 243
244 244 // Note: multianewarray for one dimension is handled inline by GraphKit::new_array.
245 245
246 246 // multianewarray for 2 dimensions
247 247 JRT_ENTRY(void, OptoRuntime::multianewarray2_C(klassOopDesc* elem_type, int len1, int len2, JavaThread *thread))
248 248 #ifndef PRODUCT
249 249 SharedRuntime::_multi2_ctr++; // multianewarray for 1 dimension
250 250 #endif
251 251 assert(check_compiled_frame(thread), "incorrect caller");
252 252 assert(oop(elem_type)->is_klass(), "not a class");
253 253 jint dims[2];
254 254 dims[0] = len1;
255 255 dims[1] = len2;
256 256 oop obj = arrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD);
257 257 deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
258 258 thread->set_vm_result(obj);
259 259 JRT_END
260 260
261 261 // multianewarray for 3 dimensions
262 262 JRT_ENTRY(void, OptoRuntime::multianewarray3_C(klassOopDesc* elem_type, int len1, int len2, int len3, JavaThread *thread))
263 263 #ifndef PRODUCT
264 264 SharedRuntime::_multi3_ctr++; // multianewarray for 1 dimension
265 265 #endif
266 266 assert(check_compiled_frame(thread), "incorrect caller");
267 267 assert(oop(elem_type)->is_klass(), "not a class");
268 268 jint dims[3];
269 269 dims[0] = len1;
270 270 dims[1] = len2;
271 271 dims[2] = len3;
272 272 oop obj = arrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD);
273 273 deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
274 274 thread->set_vm_result(obj);
275 275 JRT_END
276 276
277 277 // multianewarray for 4 dimensions
278 278 JRT_ENTRY(void, OptoRuntime::multianewarray4_C(klassOopDesc* elem_type, int len1, int len2, int len3, int len4, JavaThread *thread))
279 279 #ifndef PRODUCT
280 280 SharedRuntime::_multi4_ctr++; // multianewarray for 1 dimension
281 281 #endif
282 282 assert(check_compiled_frame(thread), "incorrect caller");
283 283 assert(oop(elem_type)->is_klass(), "not a class");
284 284 jint dims[4];
285 285 dims[0] = len1;
286 286 dims[1] = len2;
287 287 dims[2] = len3;
288 288 dims[3] = len4;
289 289 oop obj = arrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD);
290 290 deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
291 291 thread->set_vm_result(obj);
292 292 JRT_END
293 293
294 294 // multianewarray for 5 dimensions
295 295 JRT_ENTRY(void, OptoRuntime::multianewarray5_C(klassOopDesc* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread *thread))
296 296 #ifndef PRODUCT
297 297 SharedRuntime::_multi5_ctr++; // multianewarray for 1 dimension
298 298 #endif
299 299 assert(check_compiled_frame(thread), "incorrect caller");
300 300 assert(oop(elem_type)->is_klass(), "not a class");
301 301 jint dims[5];
302 302 dims[0] = len1;
303 303 dims[1] = len2;
304 304 dims[2] = len3;
305 305 dims[3] = len4;
306 306 dims[4] = len5;
307 307 oop obj = arrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD);
308 308 deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
309 309 thread->set_vm_result(obj);
310 310 JRT_END
311 311
312 312 const TypeFunc *OptoRuntime::new_instance_Type() {
313 313 // create input type (domain)
314 314 const Type **fields = TypeTuple::fields(1);
315 315 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
316 316 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
317 317
318 318 // create result type (range)
319 319 fields = TypeTuple::fields(1);
320 320 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
321 321
322 322 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
323 323
324 324 return TypeFunc::make(domain, range);
325 325 }
326 326
327 327
328 328 const TypeFunc *OptoRuntime::athrow_Type() {
329 329 // create input type (domain)
330 330 const Type **fields = TypeTuple::fields(1);
331 331 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
332 332 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
333 333
334 334 // create result type (range)
335 335 fields = TypeTuple::fields(0);
336 336
337 337 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
338 338
339 339 return TypeFunc::make(domain, range);
340 340 }
341 341
342 342
343 343 const TypeFunc *OptoRuntime::new_array_Type() {
344 344 // create input type (domain)
345 345 const Type **fields = TypeTuple::fields(2);
346 346 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
347 347 fields[TypeFunc::Parms+1] = TypeInt::INT; // array size
348 348 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
349 349
350 350 // create result type (range)
351 351 fields = TypeTuple::fields(1);
352 352 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
353 353
354 354 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
355 355
356 356 return TypeFunc::make(domain, range);
357 357 }
358 358
359 359 const TypeFunc *OptoRuntime::multianewarray_Type(int ndim) {
360 360 // create input type (domain)
361 361 const int nargs = ndim + 1;
362 362 const Type **fields = TypeTuple::fields(nargs);
363 363 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
364 364 for( int i = 1; i < nargs; i++ )
365 365 fields[TypeFunc::Parms + i] = TypeInt::INT; // array size
366 366 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+nargs, fields);
367 367
368 368 // create result type (range)
369 369 fields = TypeTuple::fields(1);
370 370 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
371 371 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
372 372
373 373 return TypeFunc::make(domain, range);
374 374 }
375 375
376 376 const TypeFunc *OptoRuntime::multianewarray2_Type() {
377 377 return multianewarray_Type(2);
378 378 }
379 379
380 380 const TypeFunc *OptoRuntime::multianewarray3_Type() {
381 381 return multianewarray_Type(3);
382 382 }
383 383
384 384 const TypeFunc *OptoRuntime::multianewarray4_Type() {
385 385 return multianewarray_Type(4);
386 386 }
387 387
388 388 const TypeFunc *OptoRuntime::multianewarray5_Type() {
389 389 return multianewarray_Type(5);
390 390 }
391 391
392 392 const TypeFunc *OptoRuntime::g1_wb_pre_Type() {
393 393 const Type **fields = TypeTuple::fields(2);
394 394 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value
395 395 fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // thread
396 396 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
397 397
398 398 // create result type (range)
399 399 fields = TypeTuple::fields(0);
400 400 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
401 401
402 402 return TypeFunc::make(domain, range);
403 403 }
404 404
405 405 const TypeFunc *OptoRuntime::g1_wb_post_Type() {
406 406
407 407 const Type **fields = TypeTuple::fields(2);
408 408 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Card addr
409 409 fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // thread
410 410 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
411 411
412 412 // create result type (range)
413 413 fields = TypeTuple::fields(0);
414 414 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
415 415
416 416 return TypeFunc::make(domain, range);
417 417 }
418 418
419 419 const TypeFunc *OptoRuntime::uncommon_trap_Type() {
420 420 // create input type (domain)
421 421 const Type **fields = TypeTuple::fields(1);
422 422 // symbolOop name of class to be loaded
423 423 fields[TypeFunc::Parms+0] = TypeInt::INT;
424 424 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
425 425
426 426 // create result type (range)
427 427 fields = TypeTuple::fields(0);
428 428 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
429 429
430 430 return TypeFunc::make(domain, range);
431 431 }
432 432
433 433 # ifdef ENABLE_ZAP_DEAD_LOCALS
434 434 // Type used for stub generation for zap_dead_locals.
435 435 // No inputs or outputs
436 436 const TypeFunc *OptoRuntime::zap_dead_locals_Type() {
437 437 // create input type (domain)
438 438 const Type **fields = TypeTuple::fields(0);
439 439 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms,fields);
440 440
441 441 // create result type (range)
442 442 fields = TypeTuple::fields(0);
443 443 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms,fields);
444 444
445 445 return TypeFunc::make(domain,range);
446 446 }
447 447 # endif
448 448
449 449
450 450 //-----------------------------------------------------------------------------
451 451 // Monitor Handling
452 452 const TypeFunc *OptoRuntime::complete_monitor_enter_Type() {
453 453 // create input type (domain)
454 454 const Type **fields = TypeTuple::fields(2);
455 455 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
456 456 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock
457 457 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
458 458
459 459 // create result type (range)
460 460 fields = TypeTuple::fields(0);
461 461
462 462 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
463 463
464 464 return TypeFunc::make(domain,range);
465 465 }
466 466
467 467
468 468 //-----------------------------------------------------------------------------
469 469 const TypeFunc *OptoRuntime::complete_monitor_exit_Type() {
470 470 // create input type (domain)
471 471 const Type **fields = TypeTuple::fields(2);
472 472 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
473 473 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock
474 474 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
475 475
476 476 // create result type (range)
477 477 fields = TypeTuple::fields(0);
478 478
479 479 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
480 480
481 481 return TypeFunc::make(domain,range);
482 482 }
483 483
484 484 const TypeFunc* OptoRuntime::flush_windows_Type() {
485 485 // create input type (domain)
486 486 const Type** fields = TypeTuple::fields(1);
487 487 fields[TypeFunc::Parms+0] = NULL; // void
488 488 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields);
489 489
490 490 // create result type
491 491 fields = TypeTuple::fields(1);
492 492 fields[TypeFunc::Parms+0] = NULL; // void
493 493 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
494 494
495 495 return TypeFunc::make(domain, range);
496 496 }
497 497
498 498 const TypeFunc* OptoRuntime::l2f_Type() {
499 499 // create input type (domain)
500 500 const Type **fields = TypeTuple::fields(2);
501 501 fields[TypeFunc::Parms+0] = TypeLong::LONG;
502 502 fields[TypeFunc::Parms+1] = Type::HALF;
503 503 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
504 504
505 505 // create result type (range)
506 506 fields = TypeTuple::fields(1);
507 507 fields[TypeFunc::Parms+0] = Type::FLOAT;
508 508 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
509 509
510 510 return TypeFunc::make(domain, range);
511 511 }
512 512
513 513 const TypeFunc* OptoRuntime::modf_Type() {
514 514 const Type **fields = TypeTuple::fields(2);
515 515 fields[TypeFunc::Parms+0] = Type::FLOAT;
516 516 fields[TypeFunc::Parms+1] = Type::FLOAT;
517 517 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
518 518
519 519 // create result type (range)
520 520 fields = TypeTuple::fields(1);
521 521 fields[TypeFunc::Parms+0] = Type::FLOAT;
522 522
523 523 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
524 524
525 525 return TypeFunc::make(domain, range);
526 526 }
527 527
528 528 const TypeFunc *OptoRuntime::Math_D_D_Type() {
529 529 // create input type (domain)
530 530 const Type **fields = TypeTuple::fields(2);
531 531 // symbolOop name of class to be loaded
532 532 fields[TypeFunc::Parms+0] = Type::DOUBLE;
533 533 fields[TypeFunc::Parms+1] = Type::HALF;
534 534 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
535 535
536 536 // create result type (range)
537 537 fields = TypeTuple::fields(2);
538 538 fields[TypeFunc::Parms+0] = Type::DOUBLE;
539 539 fields[TypeFunc::Parms+1] = Type::HALF;
540 540 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
541 541
542 542 return TypeFunc::make(domain, range);
543 543 }
544 544
545 545 const TypeFunc* OptoRuntime::Math_DD_D_Type() {
546 546 const Type **fields = TypeTuple::fields(4);
547 547 fields[TypeFunc::Parms+0] = Type::DOUBLE;
548 548 fields[TypeFunc::Parms+1] = Type::HALF;
549 549 fields[TypeFunc::Parms+2] = Type::DOUBLE;
550 550 fields[TypeFunc::Parms+3] = Type::HALF;
551 551 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+4, fields);
552 552
553 553 // create result type (range)
554 554 fields = TypeTuple::fields(2);
555 555 fields[TypeFunc::Parms+0] = Type::DOUBLE;
556 556 fields[TypeFunc::Parms+1] = Type::HALF;
557 557 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
558 558
559 559 return TypeFunc::make(domain, range);
560 560 }
561 561
562 562 //-------------- currentTimeMillis
563 563
564 564 const TypeFunc* OptoRuntime::current_time_millis_Type() {
565 565 // create input type (domain)
566 566 const Type **fields = TypeTuple::fields(0);
567 567 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+0, fields);
568 568
569 569 // create result type (range)
570 570 fields = TypeTuple::fields(2);
571 571 fields[TypeFunc::Parms+0] = TypeLong::LONG;
572 572 fields[TypeFunc::Parms+1] = Type::HALF;
573 573 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
574 574
575 575 return TypeFunc::make(domain, range);
576 576 }
577 577
578 578 // arraycopy stub variations:
579 579 enum ArrayCopyType {
580 580 ac_fast, // void(ptr, ptr, size_t)
581 581 ac_checkcast, // int(ptr, ptr, size_t, size_t, ptr)
582 582 ac_slow, // void(ptr, int, ptr, int, int)
583 583 ac_generic // int(ptr, int, ptr, int, int)
584 584 };
585 585
586 586 static const TypeFunc* make_arraycopy_Type(ArrayCopyType act) {
587 587 // create input type (domain)
588 588 int num_args = (act == ac_fast ? 3 : 5);
589 589 int num_size_args = (act == ac_fast ? 1 : act == ac_checkcast ? 2 : 0);
590 590 int argcnt = num_args;
591 591 LP64_ONLY(argcnt += num_size_args); // halfwords for lengths
592 592 const Type** fields = TypeTuple::fields(argcnt);
593 593 int argp = TypeFunc::Parms;
594 594 fields[argp++] = TypePtr::NOTNULL; // src
595 595 if (num_size_args == 0) {
596 596 fields[argp++] = TypeInt::INT; // src_pos
597 597 }
598 598 fields[argp++] = TypePtr::NOTNULL; // dest
599 599 if (num_size_args == 0) {
600 600 fields[argp++] = TypeInt::INT; // dest_pos
601 601 fields[argp++] = TypeInt::INT; // length
602 602 }
603 603 while (num_size_args-- > 0) {
604 604 fields[argp++] = TypeX_X; // size in whatevers (size_t)
605 605 LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length
606 606 }
607 607 if (act == ac_checkcast) {
608 608 fields[argp++] = TypePtr::NOTNULL; // super_klass
609 609 }
610 610 assert(argp == TypeFunc::Parms+argcnt, "correct decoding of act");
611 611 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
612 612
613 613 // create result type if needed
614 614 int retcnt = (act == ac_checkcast || act == ac_generic ? 1 : 0);
615 615 fields = TypeTuple::fields(1);
616 616 if (retcnt == 0)
617 617 fields[TypeFunc::Parms+0] = NULL; // void
618 618 else
619 619 fields[TypeFunc::Parms+0] = TypeInt::INT; // status result, if needed
620 620 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+retcnt, fields);
621 621 return TypeFunc::make(domain, range);
622 622 }
623 623
624 624 const TypeFunc* OptoRuntime::fast_arraycopy_Type() {
625 625 // This signature is simple: Two base pointers and a size_t.
626 626 return make_arraycopy_Type(ac_fast);
627 627 }
628 628
629 629 const TypeFunc* OptoRuntime::checkcast_arraycopy_Type() {
630 630 // An extension of fast_arraycopy_Type which adds type checking.
631 631 return make_arraycopy_Type(ac_checkcast);
632 632 }
633 633
634 634 const TypeFunc* OptoRuntime::slow_arraycopy_Type() {
635 635 // This signature is exactly the same as System.arraycopy.
636 636 // There are no intptr_t (int/long) arguments.
637 637 return make_arraycopy_Type(ac_slow);
638 638 }
639 639
640 640 const TypeFunc* OptoRuntime::generic_arraycopy_Type() {
641 641 // This signature is like System.arraycopy, except that it returns status.
642 642 return make_arraycopy_Type(ac_generic);
643 643 }
644 644
645 645
646 646 //------------- Interpreter state access for on stack replacement
647 647 const TypeFunc* OptoRuntime::osr_end_Type() {
648 648 // create input type (domain)
649 649 const Type **fields = TypeTuple::fields(1);
650 650 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // OSR temp buf
651 651 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
652 652
653 653 // create result type
654 654 fields = TypeTuple::fields(1);
655 655 // fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // locked oop
656 656 fields[TypeFunc::Parms+0] = NULL; // void
657 657 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
658 658 return TypeFunc::make(domain, range);
659 659 }
660 660
661 661 //-------------- methodData update helpers
662 662
663 663 const TypeFunc* OptoRuntime::profile_receiver_type_Type() {
664 664 // create input type (domain)
665 665 const Type **fields = TypeTuple::fields(2);
666 666 fields[TypeFunc::Parms+0] = TypeAryPtr::NOTNULL; // methodData pointer
667 667 fields[TypeFunc::Parms+1] = TypeInstPtr::BOTTOM; // receiver oop
668 668 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
669 669
670 670 // create result type
671 671 fields = TypeTuple::fields(1);
672 672 fields[TypeFunc::Parms+0] = NULL; // void
673 673 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
674 674 return TypeFunc::make(domain,range);
675 675 }
676 676
677 677 JRT_LEAF(void, OptoRuntime::profile_receiver_type_C(DataLayout* data, oopDesc* receiver))
678 678 if (receiver == NULL) return;
679 679 klassOop receiver_klass = receiver->klass();
680 680
681 681 intptr_t* mdp = ((intptr_t*)(data)) + DataLayout::header_size_in_cells();
682 682 int empty_row = -1; // free row, if any is encountered
683 683
684 684 // ReceiverTypeData* vc = new ReceiverTypeData(mdp);
685 685 for (uint row = 0; row < ReceiverTypeData::row_limit(); row++) {
686 686 // if (vc->receiver(row) == receiver_klass)
687 687 int receiver_off = ReceiverTypeData::receiver_cell_index(row);
688 688 intptr_t row_recv = *(mdp + receiver_off);
689 689 if (row_recv == (intptr_t) receiver_klass) {
690 690 // vc->set_receiver_count(row, vc->receiver_count(row) + DataLayout::counter_increment);
691 691 int count_off = ReceiverTypeData::receiver_count_cell_index(row);
692 692 *(mdp + count_off) += DataLayout::counter_increment;
693 693 return;
694 694 } else if (row_recv == 0) {
695 695 // else if (vc->receiver(row) == NULL)
696 696 empty_row = (int) row;
697 697 }
698 698 }
699 699
700 700 if (empty_row != -1) {
701 701 int receiver_off = ReceiverTypeData::receiver_cell_index(empty_row);
702 702 // vc->set_receiver(empty_row, receiver_klass);
703 703 *(mdp + receiver_off) = (intptr_t) receiver_klass;
704 704 // vc->set_receiver_count(empty_row, DataLayout::counter_increment);
705 705 int count_off = ReceiverTypeData::receiver_count_cell_index(empty_row);
706 706 *(mdp + count_off) = DataLayout::counter_increment;
707 707 }
708 708 JRT_END
709 709
710 710 //-----------------------------------------------------------------------------
711 711 // implicit exception support.
712 712
713 713 static void report_null_exception_in_code_cache(address exception_pc) {
714 714 ResourceMark rm;
715 715 CodeBlob* n = CodeCache::find_blob(exception_pc);
716 716 if (n != NULL) {
717 717 tty->print_cr("#");
718 718 tty->print_cr("# HotSpot Runtime Error, null exception in generated code");
719 719 tty->print_cr("#");
720 720 tty->print_cr("# pc where exception happened = " INTPTR_FORMAT, exception_pc);
721 721
722 722 if (n->is_nmethod()) {
723 723 methodOop method = ((nmethod*)n)->method();
724 724 tty->print_cr("# Method where it happened %s.%s ", Klass::cast(method->method_holder())->name()->as_C_string(), method->name()->as_C_string());
725 725 tty->print_cr("#");
726 726 if (ShowMessageBoxOnError && UpdateHotSpotCompilerFileOnError) {
727 727 const char* title = "HotSpot Runtime Error";
728 728 const char* question = "Do you want to exclude compilation of this method in future runs?";
729 729 if (os::message_box(title, question)) {
730 730 CompilerOracle::append_comment_to_file("");
731 731 CompilerOracle::append_comment_to_file("Null exception in compiled code resulted in the following exclude");
732 732 CompilerOracle::append_comment_to_file("");
733 733 CompilerOracle::append_exclude_to_file(method);
734 734 tty->print_cr("#");
735 735 tty->print_cr("# %s has been updated to exclude the specified method", CompileCommandFile);
736 736 tty->print_cr("#");
737 737 }
738 738 }
739 739 fatal("Implicit null exception happened in compiled method");
740 740 } else {
741 741 n->print();
742 742 fatal("Implicit null exception happened in generated stub");
743 743 }
744 744 }
745 745 fatal("Implicit null exception at wrong place");
746 746 }
747 747
748 748
749 749 //-------------------------------------------------------------------------------------
750 750 // register policy
751 751
752 752 bool OptoRuntime::is_callee_saved_register(MachRegisterNumbers reg) {
753 753 assert(reg >= 0 && reg < _last_Mach_Reg, "must be a machine register");
754 754 switch (register_save_policy[reg]) {
755 755 case 'C': return false; //SOC
756 756 case 'E': return true ; //SOE
757 757 case 'N': return false; //NS
758 758 case 'A': return false; //AS
759 759 }
760 760 ShouldNotReachHere();
761 761 return false;
762 762 }
763 763
764 764 //-----------------------------------------------------------------------
765 765 // Exceptions
766 766 //
767 767
768 768 static void trace_exception(oop exception_oop, address exception_pc, const char* msg) PRODUCT_RETURN;
769 769
770 770 // The method is an entry that is always called by a C++ method not
771 771 // directly from compiled code. Compiled code will call the C++ method following.
772 772 // We can't allow async exception to be installed during exception processing.
773 773 JRT_ENTRY_NO_ASYNC(address, OptoRuntime::handle_exception_C_helper(JavaThread* thread, nmethod* &nm))
774 774
775 775 // Do not confuse exception_oop with pending_exception. The exception_oop
776 776 // is only used to pass arguments into the method. Not for general
777 777 // exception handling. DO NOT CHANGE IT to use pending_exception, since
778 778 // the runtime stubs checks this on exit.
779 779 assert(thread->exception_oop() != NULL, "exception oop is found");
780 780 address handler_address = NULL;
781 781
782 782 Handle exception(thread, thread->exception_oop());
783 783
784 784 if (TraceExceptions) {
785 785 trace_exception(exception(), thread->exception_pc(), "");
786 786 }
787 787 // for AbortVMOnException flag
788 788 NOT_PRODUCT(Exceptions::debug_check_abort(exception));
789 789
790 790 #ifdef ASSERT
791 791 if (!(exception->is_a(SystemDictionary::throwable_klass()))) {
792 792 // should throw an exception here
793 793 ShouldNotReachHere();
794 794 }
795 795 #endif
796 796
797 797
798 798 // new exception handling: this method is entered only from adapters
799 799 // exceptions from compiled java methods are handled in compiled code
800 800 // using rethrow node
801 801
802 802 address pc = thread->exception_pc();
803 803 nm = CodeCache::find_nmethod(pc);
804 804 assert(nm != NULL, "No NMethod found");
805 805 if (nm->is_native_method()) {
806 806 fatal("Native mathod should not have path to exception handling");
807 807 } else {
808 808 // we are switching to old paradigm: search for exception handler in caller_frame
809 809 // instead in exception handler of caller_frame.sender()
810 810
811 811 if (JvmtiExport::can_post_exceptions()) {
812 812 // "Full-speed catching" is not necessary here,
813 813 // since we're notifying the VM on every catch.
814 814 // Force deoptimization and the rest of the lookup
815 815 // will be fine.
816 816 deoptimize_caller_frame(thread, true);
817 817 }
818 818
819 819 // Check the stack guard pages. If enabled, look for handler in this frame;
820 820 // otherwise, forcibly unwind the frame.
821 821 //
822 822 // 4826555: use default current sp for reguard_stack instead of &nm: it's more accurate.
823 823 bool force_unwind = !thread->reguard_stack();
824 824 bool deopting = false;
825 825 if (nm->is_deopt_pc(pc)) {
826 826 deopting = true;
827 827 RegisterMap map(thread, false);
828 828 frame deoptee = thread->last_frame().sender(&map);
829 829 assert(deoptee.is_deoptimized_frame(), "must be deopted");
830 830 // Adjust the pc back to the original throwing pc
831 831 pc = deoptee.pc();
832 832 }
833 833
834 834 // If we are forcing an unwind because of stack overflow then deopt is
835 835 // irrelevant sice we are throwing the frame away anyway.
836 836
837 837 if (deopting && !force_unwind) {
838 838 handler_address = SharedRuntime::deopt_blob()->unpack_with_exception();
839 839 } else {
840 840
841 841 handler_address =
842 842 force_unwind ? NULL : nm->handler_for_exception_and_pc(exception, pc);
843 843
844 844 if (handler_address == NULL) {
845 845 handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true);
846 846 assert (handler_address != NULL, "must have compiled handler");
847 847 // Update the exception cache only when the unwind was not forced.
848 848 if (!force_unwind) {
↓ open down ↓ |
836 lines elided |
↑ open up ↑ |
849 849 nm->add_handler_for_exception_and_pc(exception,pc,handler_address);
850 850 }
851 851 } else {
852 852 assert(handler_address == SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true), "Must be the same");
853 853 }
854 854 }
855 855
856 856 thread->set_exception_pc(pc);
857 857 thread->set_exception_handler_pc(handler_address);
858 858 thread->set_exception_stack_size(0);
859 +
860 + // Check if the exception PC is a MethodHandle call.
861 + thread->set_is_method_handle_exception(nm->is_method_handle_return(pc));
859 862 }
860 863
861 864 // Restore correct return pc. Was saved above.
862 865 thread->set_exception_oop(exception());
863 866 return handler_address;
864 867
865 868 JRT_END
866 869
867 870 // We are entering here from exception_blob
868 871 // If there is a compiled exception handler in this method, we will continue there;
869 872 // otherwise we will unwind the stack and continue at the caller of top frame method
870 873 // Note we enter without the usual JRT wrapper. We will call a helper routine that
871 874 // will do the normal VM entry. We do it this way so that we can see if the nmethod
872 875 // we looked up the handler for has been deoptimized in the meantime. If it has been
873 876 // we must not use the handler and instread return the deopt blob.
874 877 address OptoRuntime::handle_exception_C(JavaThread* thread) {
875 878 //
876 879 // We are in Java not VM and in debug mode we have a NoHandleMark
877 880 //
878 881 #ifndef PRODUCT
879 882 SharedRuntime::_find_handler_ctr++; // find exception handler
880 883 #endif
881 884 debug_only(NoHandleMark __hm;)
882 885 nmethod* nm = NULL;
883 886 address handler_address = NULL;
884 887 {
885 888 // Enter the VM
886 889
887 890 ResetNoHandleMark rnhm;
888 891 handler_address = handle_exception_C_helper(thread, nm);
889 892 }
890 893
891 894 // Back in java: Use no oops, DON'T safepoint
892 895
893 896 // Now check to see if the handler we are returning is in a now
894 897 // deoptimized frame
895 898
896 899 if (nm != NULL) {
897 900 RegisterMap map(thread, false);
898 901 frame caller = thread->last_frame().sender(&map);
899 902 #ifdef ASSERT
900 903 assert(caller.is_compiled_frame(), "must be");
901 904 #endif // ASSERT
902 905 if (caller.is_deoptimized_frame()) {
903 906 handler_address = SharedRuntime::deopt_blob()->unpack_with_exception();
904 907 }
905 908 }
906 909 return handler_address;
907 910 }
908 911
909 912 //------------------------------rethrow----------------------------------------
910 913 // We get here after compiled code has executed a 'RethrowNode'. The callee
911 914 // is either throwing or rethrowing an exception. The callee-save registers
912 915 // have been restored, synchronized objects have been unlocked and the callee
913 916 // stack frame has been removed. The return address was passed in.
914 917 // Exception oop is passed as the 1st argument. This routine is then called
915 918 // from the stub. On exit, we know where to jump in the caller's code.
916 919 // After this C code exits, the stub will pop his frame and end in a jump
917 920 // (instead of a return). We enter the caller's default handler.
918 921 //
919 922 // This must be JRT_LEAF:
920 923 // - caller will not change its state as we cannot block on exit,
921 924 // therefore raw_exception_handler_for_return_address is all it takes
922 925 // to handle deoptimized blobs
923 926 //
924 927 // However, there needs to be a safepoint check in the middle! So compiled
925 928 // safepoints are completely watertight.
926 929 //
927 930 // Thus, it cannot be a leaf since it contains the No_GC_Verifier.
928 931 //
929 932 // *THIS IS NOT RECOMMENDED PROGRAMMING STYLE*
930 933 //
931 934 address OptoRuntime::rethrow_C(oopDesc* exception, JavaThread* thread, address ret_pc) {
932 935 #ifndef PRODUCT
933 936 SharedRuntime::_rethrow_ctr++; // count rethrows
934 937 #endif
935 938 assert (exception != NULL, "should have thrown a NULLPointerException");
936 939 #ifdef ASSERT
937 940 if (!(exception->is_a(SystemDictionary::throwable_klass()))) {
938 941 // should throw an exception here
939 942 ShouldNotReachHere();
940 943 }
941 944 #endif
942 945
943 946 thread->set_vm_result(exception);
944 947 // Frame not compiled (handles deoptimization blob)
945 948 return SharedRuntime::raw_exception_handler_for_return_address(ret_pc);
946 949 }
947 950
948 951
949 952 const TypeFunc *OptoRuntime::rethrow_Type() {
950 953 // create input type (domain)
951 954 const Type **fields = TypeTuple::fields(1);
952 955 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop
953 956 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
954 957
955 958 // create result type (range)
956 959 fields = TypeTuple::fields(1);
957 960 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop
958 961 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
959 962
960 963 return TypeFunc::make(domain, range);
961 964 }
962 965
963 966
964 967 void OptoRuntime::deoptimize_caller_frame(JavaThread *thread, bool doit) {
965 968 // Deoptimize frame
966 969 if (doit) {
967 970 // Called from within the owner thread, so no need for safepoint
968 971 RegisterMap reg_map(thread);
969 972 frame stub_frame = thread->last_frame();
970 973 assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
971 974 frame caller_frame = stub_frame.sender(®_map);
972 975
973 976 VM_DeoptimizeFrame deopt(thread, caller_frame.id());
974 977 VMThread::execute(&deopt);
975 978 }
976 979 }
977 980
978 981
979 982 const TypeFunc *OptoRuntime::register_finalizer_Type() {
980 983 // create input type (domain)
981 984 const Type **fields = TypeTuple::fields(1);
982 985 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver
983 986 // // The JavaThread* is passed to each routine as the last argument
984 987 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
985 988 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
986 989
987 990 // create result type (range)
988 991 fields = TypeTuple::fields(0);
989 992
990 993 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
991 994
992 995 return TypeFunc::make(domain,range);
993 996 }
994 997
995 998
996 999 //-----------------------------------------------------------------------------
997 1000 // Dtrace support. entry and exit probes have the same signature
998 1001 const TypeFunc *OptoRuntime::dtrace_method_entry_exit_Type() {
999 1002 // create input type (domain)
1000 1003 const Type **fields = TypeTuple::fields(2);
1001 1004 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1002 1005 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // methodOop; Method we are entering
1003 1006 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1004 1007
1005 1008 // create result type (range)
1006 1009 fields = TypeTuple::fields(0);
1007 1010
1008 1011 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1009 1012
1010 1013 return TypeFunc::make(domain,range);
1011 1014 }
1012 1015
1013 1016 const TypeFunc *OptoRuntime::dtrace_object_alloc_Type() {
1014 1017 // create input type (domain)
1015 1018 const Type **fields = TypeTuple::fields(2);
1016 1019 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1017 1020 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object
1018 1021
1019 1022 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1020 1023
1021 1024 // create result type (range)
1022 1025 fields = TypeTuple::fields(0);
1023 1026
1024 1027 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1025 1028
1026 1029 return TypeFunc::make(domain,range);
1027 1030 }
1028 1031
1029 1032
1030 1033 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer(oopDesc* obj, JavaThread* thread))
1031 1034 assert(obj->is_oop(), "must be a valid oop");
1032 1035 assert(obj->klass()->klass_part()->has_finalizer(), "shouldn't be here otherwise");
1033 1036 instanceKlass::register_finalizer(instanceOop(obj), CHECK);
1034 1037 JRT_END
1035 1038
1036 1039 //-----------------------------------------------------------------------------
1037 1040
1038 1041 NamedCounter * volatile OptoRuntime::_named_counters = NULL;
1039 1042
1040 1043 //
1041 1044 // dump the collected NamedCounters.
1042 1045 //
1043 1046 void OptoRuntime::print_named_counters() {
1044 1047 int total_lock_count = 0;
1045 1048 int eliminated_lock_count = 0;
1046 1049
1047 1050 NamedCounter* c = _named_counters;
1048 1051 while (c) {
1049 1052 if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) {
1050 1053 int count = c->count();
1051 1054 if (count > 0) {
1052 1055 bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter;
1053 1056 if (Verbose) {
1054 1057 tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : "");
1055 1058 }
1056 1059 total_lock_count += count;
1057 1060 if (eliminated) {
1058 1061 eliminated_lock_count += count;
1059 1062 }
1060 1063 }
1061 1064 } else if (c->tag() == NamedCounter::BiasedLockingCounter) {
1062 1065 BiasedLockingCounters* blc = ((BiasedLockingNamedCounter*)c)->counters();
1063 1066 if (blc->nonzero()) {
1064 1067 tty->print_cr("%s", c->name());
1065 1068 blc->print_on(tty);
1066 1069 }
1067 1070 }
1068 1071 c = c->next();
1069 1072 }
1070 1073 if (total_lock_count > 0) {
1071 1074 tty->print_cr("dynamic locks: %d", total_lock_count);
1072 1075 if (eliminated_lock_count) {
1073 1076 tty->print_cr("eliminated locks: %d (%d%%)", eliminated_lock_count,
1074 1077 (int)(eliminated_lock_count * 100.0 / total_lock_count));
1075 1078 }
1076 1079 }
1077 1080 }
1078 1081
1079 1082 //
1080 1083 // Allocate a new NamedCounter. The JVMState is used to generate the
1081 1084 // name which consists of method@line for the inlining tree.
1082 1085 //
1083 1086
1084 1087 NamedCounter* OptoRuntime::new_named_counter(JVMState* youngest_jvms, NamedCounter::CounterTag tag) {
1085 1088 int max_depth = youngest_jvms->depth();
1086 1089
1087 1090 // Visit scopes from youngest to oldest.
1088 1091 bool first = true;
1089 1092 stringStream st;
1090 1093 for (int depth = max_depth; depth >= 1; depth--) {
1091 1094 JVMState* jvms = youngest_jvms->of_depth(depth);
1092 1095 ciMethod* m = jvms->has_method() ? jvms->method() : NULL;
1093 1096 if (!first) {
1094 1097 st.print(" ");
1095 1098 } else {
1096 1099 first = false;
1097 1100 }
1098 1101 int bci = jvms->bci();
1099 1102 if (bci < 0) bci = 0;
1100 1103 st.print("%s.%s@%d", m->holder()->name()->as_utf8(), m->name()->as_utf8(), bci);
1101 1104 // To print linenumbers instead of bci use: m->line_number_from_bci(bci)
1102 1105 }
1103 1106 NamedCounter* c;
1104 1107 if (tag == NamedCounter::BiasedLockingCounter) {
1105 1108 c = new BiasedLockingNamedCounter(strdup(st.as_string()));
1106 1109 } else {
1107 1110 c = new NamedCounter(strdup(st.as_string()), tag);
1108 1111 }
1109 1112
1110 1113 // atomically add the new counter to the head of the list. We only
1111 1114 // add counters so this is safe.
1112 1115 NamedCounter* head;
1113 1116 do {
1114 1117 head = _named_counters;
1115 1118 c->set_next(head);
1116 1119 } while (Atomic::cmpxchg_ptr(c, &_named_counters, head) != head);
1117 1120 return c;
1118 1121 }
1119 1122
1120 1123 //-----------------------------------------------------------------------------
1121 1124 // Non-product code
1122 1125 #ifndef PRODUCT
1123 1126
1124 1127 int trace_exception_counter = 0;
1125 1128 static void trace_exception(oop exception_oop, address exception_pc, const char* msg) {
1126 1129 ttyLocker ttyl;
1127 1130 trace_exception_counter++;
1128 1131 tty->print("%d [Exception (%s): ", trace_exception_counter, msg);
1129 1132 exception_oop->print_value();
1130 1133 tty->print(" in ");
1131 1134 CodeBlob* blob = CodeCache::find_blob(exception_pc);
1132 1135 if (blob->is_nmethod()) {
1133 1136 ((nmethod*)blob)->method()->print_value();
1134 1137 } else if (blob->is_runtime_stub()) {
1135 1138 tty->print("<runtime-stub>");
1136 1139 } else {
1137 1140 tty->print("<unknown>");
1138 1141 }
1139 1142 tty->print(" at " INTPTR_FORMAT, exception_pc);
1140 1143 tty->print_cr("]");
1141 1144 }
1142 1145
1143 1146 #endif // PRODUCT
1144 1147
1145 1148
1146 1149 # ifdef ENABLE_ZAP_DEAD_LOCALS
1147 1150 // Called from call sites in compiled code with oop maps (actually safepoints)
1148 1151 // Zaps dead locals in first java frame.
1149 1152 // Is entry because may need to lock to generate oop maps
1150 1153 // Currently, only used for compiler frames, but someday may be used
1151 1154 // for interpreter frames, too.
1152 1155
1153 1156 int OptoRuntime::ZapDeadCompiledLocals_count = 0;
1154 1157
1155 1158 // avoid pointers to member funcs with these helpers
1156 1159 static bool is_java_frame( frame* f) { return f->is_java_frame(); }
1157 1160 static bool is_native_frame(frame* f) { return f->is_native_frame(); }
1158 1161
1159 1162
1160 1163 void OptoRuntime::zap_dead_java_or_native_locals(JavaThread* thread,
1161 1164 bool (*is_this_the_right_frame_to_zap)(frame*)) {
1162 1165 assert(JavaThread::current() == thread, "is this needed?");
1163 1166
1164 1167 if ( !ZapDeadCompiledLocals ) return;
1165 1168
1166 1169 bool skip = false;
1167 1170
1168 1171 if ( ZapDeadCompiledLocalsFirst == 0 ) ; // nothing special
1169 1172 else if ( ZapDeadCompiledLocalsFirst > ZapDeadCompiledLocals_count ) skip = true;
1170 1173 else if ( ZapDeadCompiledLocalsFirst == ZapDeadCompiledLocals_count )
1171 1174 warning("starting zapping after skipping");
1172 1175
1173 1176 if ( ZapDeadCompiledLocalsLast == -1 ) ; // nothing special
1174 1177 else if ( ZapDeadCompiledLocalsLast < ZapDeadCompiledLocals_count ) skip = true;
1175 1178 else if ( ZapDeadCompiledLocalsLast == ZapDeadCompiledLocals_count )
1176 1179 warning("about to zap last zap");
1177 1180
1178 1181 ++ZapDeadCompiledLocals_count; // counts skipped zaps, too
1179 1182
1180 1183 if ( skip ) return;
1181 1184
1182 1185 // find java frame and zap it
1183 1186
1184 1187 for (StackFrameStream sfs(thread); !sfs.is_done(); sfs.next()) {
1185 1188 if (is_this_the_right_frame_to_zap(sfs.current()) ) {
1186 1189 sfs.current()->zap_dead_locals(thread, sfs.register_map());
1187 1190 return;
1188 1191 }
1189 1192 }
1190 1193 warning("no frame found to zap in zap_dead_Java_locals_C");
1191 1194 }
1192 1195
1193 1196 JRT_LEAF(void, OptoRuntime::zap_dead_Java_locals_C(JavaThread* thread))
1194 1197 zap_dead_java_or_native_locals(thread, is_java_frame);
1195 1198 JRT_END
1196 1199
1197 1200 // The following does not work because for one thing, the
1198 1201 // thread state is wrong; it expects java, but it is native.
1199 1202 // Also, the invariants in a native stub are different and
1200 1203 // I'm not sure it is safe to have a MachCalRuntimeDirectNode
1201 1204 // in there.
1202 1205 // So for now, we do not zap in native stubs.
1203 1206
1204 1207 JRT_LEAF(void, OptoRuntime::zap_dead_native_locals_C(JavaThread* thread))
1205 1208 zap_dead_java_or_native_locals(thread, is_native_frame);
1206 1209 JRT_END
1207 1210
1208 1211 # endif
↓ open down ↓ |
340 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX