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