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