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