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 */
24
25 #include "classfile/vmClasses.hpp"
26 #include "classfile/vmSymbols.hpp"
27 #include "code/codeCache.hpp"
28 #include "code/compiledIC.hpp"
29 #include "code/nmethod.hpp"
30 #include "code/pcDesc.hpp"
31 #include "code/scopeDesc.hpp"
32 #include "code/vtableStubs.hpp"
33 #include "compiler/compilationMemoryStatistic.hpp"
34 #include "compiler/compileBroker.hpp"
35 #include "compiler/oopMap.hpp"
36 #include "gc/g1/g1HeapRegion.hpp"
37 #include "gc/shared/barrierSet.hpp"
38 #include "gc/shared/collectedHeap.hpp"
39 #include "gc/shared/gcLocker.hpp"
40 #include "interpreter/bytecode.hpp"
41 #include "interpreter/interpreter.hpp"
42 #include "interpreter/linkResolver.hpp"
43 #include "logging/log.hpp"
44 #include "logging/logStream.hpp"
45 #include "memory/oopFactory.hpp"
46 #include "memory/resourceArea.hpp"
47 #include "oops/klass.inline.hpp"
48 #include "oops/objArrayKlass.hpp"
49 #include "oops/oop.inline.hpp"
50 #include "oops/typeArrayOop.inline.hpp"
51 #include "opto/ad.hpp"
52 #include "opto/addnode.hpp"
53 #include "opto/callnode.hpp"
54 #include "opto/cfgnode.hpp"
55 #include "opto/graphKit.hpp"
56 #include "opto/machnode.hpp"
57 #include "opto/matcher.hpp"
58 #include "opto/memnode.hpp"
59 #include "opto/mulnode.hpp"
60 #include "opto/output.hpp"
61 #include "opto/runtime.hpp"
62 #include "opto/subnode.hpp"
63 #include "prims/jvmtiExport.hpp"
64 #include "runtime/atomicAccess.hpp"
65 #include "runtime/frame.inline.hpp"
66 #include "runtime/handles.inline.hpp"
67 #include "runtime/interfaceSupport.inline.hpp"
68 #include "runtime/javaCalls.hpp"
69 #include "runtime/mountUnmountDisabler.hpp"
70 #include "runtime/sharedRuntime.hpp"
71 #include "runtime/signature.hpp"
72 #include "runtime/stackWatermarkSet.hpp"
73 #include "runtime/synchronizer.hpp"
74 #include "runtime/threadWXSetters.inline.hpp"
75 #include "runtime/vframe.hpp"
76 #include "runtime/vframe_hp.hpp"
77 #include "runtime/vframeArray.hpp"
78 #include "utilities/copy.hpp"
79 #include "utilities/preserveException.hpp"
80
81
82 // For debugging purposes:
83 // To force FullGCALot inside a runtime function, add the following two lines
84 //
85 // Universe::release_fullgc_alot_dummy();
86 // Universe::heap()->collect();
87 //
88 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
89
90
91 #define C2_BLOB_FIELD_DEFINE(name, type) \
92 type* OptoRuntime:: BLOB_FIELD_NAME(name) = nullptr;
93 #define C2_STUB_FIELD_NAME(name) _ ## name ## _Java
94 #define C2_STUB_FIELD_DEFINE(name, f, t, r) \
95 address OptoRuntime:: C2_STUB_FIELD_NAME(name) = nullptr;
96 C2_STUBS_DO(C2_BLOB_FIELD_DEFINE, C2_STUB_FIELD_DEFINE)
97 #undef C2_BLOB_FIELD_DEFINE
98 #undef C2_STUB_FIELD_DEFINE
99
100 // This should be called in an assertion at the start of OptoRuntime routines
101 // which are entered from compiled code (all of them)
102 #ifdef ASSERT
103 static bool check_compiled_frame(JavaThread* thread) {
104 assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
105 RegisterMap map(thread,
106 RegisterMap::UpdateMap::skip,
107 RegisterMap::ProcessFrames::include,
108 RegisterMap::WalkContinuation::skip);
109 frame caller = thread->last_frame().sender(&map);
110 assert(caller.is_compiled_frame(), "not being called from compiled like code");
111 return true;
112 }
113 #endif // ASSERT
114
115 /*
116 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, return_pc) \
117 var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, return_pc); \
118 if (var == nullptr) { return false; }
119 */
135 // from the stub name by appending suffix '_C'. However, in two cases
136 // a common target method also needs to be called from shared runtime
137 // stubs. In these two cases the opto stubs rely on method
138 // imlementations defined in class SharedRuntime. The following
139 // defines temporarily rebind the generated names to reference the
140 // relevant implementations.
141
142 #define GEN_C2_STUB(name, fancy_jump, pass_tls, pass_retpc ) \
143 C2_STUB_FIELD_NAME(name) = \
144 generate_stub(env, \
145 C2_STUB_TYPEFUNC(name), \
146 C2_STUB_C_FUNC(name), \
147 C2_STUB_NAME(name), \
148 C2_STUB_ID(name), \
149 fancy_jump, \
150 pass_tls, \
151 pass_retpc); \
152 if (C2_STUB_FIELD_NAME(name) == nullptr) { return false; } \
153
154 bool OptoRuntime::generate(ciEnv* env) {
155
156 C2_STUBS_DO(GEN_C2_BLOB, GEN_C2_STUB)
157
158 return true;
159 }
160
161 #undef GEN_C2_BLOB
162
163 #undef C2_STUB_FIELD_NAME
164 #undef C2_STUB_TYPEFUNC
165 #undef C2_STUB_C_FUNC
166 #undef C2_STUB_NAME
167 #undef GEN_C2_STUB
168
169 // #undef gen
170
171 const TypeFunc* OptoRuntime::_new_instance_Type = nullptr;
172 const TypeFunc* OptoRuntime::_new_array_Type = nullptr;
173 const TypeFunc* OptoRuntime::_multianewarray2_Type = nullptr;
174 const TypeFunc* OptoRuntime::_multianewarray3_Type = nullptr;
176 const TypeFunc* OptoRuntime::_multianewarray5_Type = nullptr;
177 const TypeFunc* OptoRuntime::_multianewarrayN_Type = nullptr;
178 const TypeFunc* OptoRuntime::_complete_monitor_enter_Type = nullptr;
179 const TypeFunc* OptoRuntime::_complete_monitor_exit_Type = nullptr;
180 const TypeFunc* OptoRuntime::_monitor_notify_Type = nullptr;
181 const TypeFunc* OptoRuntime::_uncommon_trap_Type = nullptr;
182 const TypeFunc* OptoRuntime::_athrow_Type = nullptr;
183 const TypeFunc* OptoRuntime::_rethrow_Type = nullptr;
184 const TypeFunc* OptoRuntime::_Math_D_D_Type = nullptr;
185 const TypeFunc* OptoRuntime::_Math_DD_D_Type = nullptr;
186 const TypeFunc* OptoRuntime::_modf_Type = nullptr;
187 const TypeFunc* OptoRuntime::_l2f_Type = nullptr;
188 const TypeFunc* OptoRuntime::_void_long_Type = nullptr;
189 const TypeFunc* OptoRuntime::_void_void_Type = nullptr;
190 const TypeFunc* OptoRuntime::_jfr_write_checkpoint_Type = nullptr;
191 const TypeFunc* OptoRuntime::_flush_windows_Type = nullptr;
192 const TypeFunc* OptoRuntime::_fast_arraycopy_Type = nullptr;
193 const TypeFunc* OptoRuntime::_checkcast_arraycopy_Type = nullptr;
194 const TypeFunc* OptoRuntime::_generic_arraycopy_Type = nullptr;
195 const TypeFunc* OptoRuntime::_slow_arraycopy_Type = nullptr;
196 const TypeFunc* OptoRuntime::_unsafe_setmemory_Type = nullptr;
197 const TypeFunc* OptoRuntime::_array_fill_Type = nullptr;
198 const TypeFunc* OptoRuntime::_array_sort_Type = nullptr;
199 const TypeFunc* OptoRuntime::_array_partition_Type = nullptr;
200 const TypeFunc* OptoRuntime::_aescrypt_block_Type = nullptr;
201 const TypeFunc* OptoRuntime::_cipherBlockChaining_aescrypt_Type = nullptr;
202 const TypeFunc* OptoRuntime::_electronicCodeBook_aescrypt_Type = nullptr;
203 const TypeFunc* OptoRuntime::_counterMode_aescrypt_Type = nullptr;
204 const TypeFunc* OptoRuntime::_galoisCounterMode_aescrypt_Type = nullptr;
205 const TypeFunc* OptoRuntime::_digestBase_implCompress_with_sha3_Type = nullptr;
206 const TypeFunc* OptoRuntime::_digestBase_implCompress_without_sha3_Type = nullptr;
207 const TypeFunc* OptoRuntime::_digestBase_implCompressMB_with_sha3_Type = nullptr;
208 const TypeFunc* OptoRuntime::_digestBase_implCompressMB_without_sha3_Type = nullptr;
209 const TypeFunc* OptoRuntime::_double_keccak_Type = nullptr;
210 const TypeFunc* OptoRuntime::_multiplyToLen_Type = nullptr;
211 const TypeFunc* OptoRuntime::_montgomeryMultiply_Type = nullptr;
212 const TypeFunc* OptoRuntime::_montgomerySquare_Type = nullptr;
213 const TypeFunc* OptoRuntime::_squareToLen_Type = nullptr;
214 const TypeFunc* OptoRuntime::_mulAdd_Type = nullptr;
215 const TypeFunc* OptoRuntime::_bigIntegerShift_Type = nullptr;
237 const TypeFunc* OptoRuntime::_updateBytesCRC32_Type = nullptr;
238 const TypeFunc* OptoRuntime::_updateBytesCRC32C_Type = nullptr;
239 const TypeFunc* OptoRuntime::_updateBytesAdler32_Type = nullptr;
240 const TypeFunc* OptoRuntime::_osr_end_Type = nullptr;
241 const TypeFunc* OptoRuntime::_register_finalizer_Type = nullptr;
242 const TypeFunc* OptoRuntime::_vthread_transition_Type = nullptr;
243 #if INCLUDE_JFR
244 const TypeFunc* OptoRuntime::_class_id_load_barrier_Type = nullptr;
245 #endif // INCLUDE_JFR
246 const TypeFunc* OptoRuntime::_dtrace_method_entry_exit_Type = nullptr;
247 const TypeFunc* OptoRuntime::_dtrace_object_alloc_Type = nullptr;
248
249 // Helper method to do generation of RunTimeStub's
250 address OptoRuntime::generate_stub(ciEnv* env,
251 TypeFunc_generator gen, address C_function,
252 const char *name, StubId stub_id,
253 int is_fancy_jump, bool pass_tls,
254 bool return_pc) {
255
256 // Matching the default directive, we currently have no method to match.
257 DirectiveSet* directive = DirectivesStack::getDefaultDirective(CompileBroker::compiler(CompLevel_full_optimization));
258 CompilationMemoryStatisticMark cmsm(directive);
259 ResourceMark rm;
260 Compile C(env, gen, C_function, name, stub_id, is_fancy_jump, pass_tls, return_pc, directive);
261 DirectivesStack::release(directive);
262 return C.stub_entry_point();
263 }
264
265 const char* OptoRuntime::stub_name(address entry) {
266 #ifndef PRODUCT
267 CodeBlob* cb = CodeCache::find_blob(entry);
268 RuntimeStub* rs =(RuntimeStub *)cb;
269 assert(rs != nullptr && rs->is_runtime_stub(), "not a runtime stub");
270 return rs->name();
271 #else
272 // Fast implementation for product mode (maybe it should be inlined too)
273 return "runtime stub";
274 #endif
275 }
276
277 // local methods passed as arguments to stub generator that forward
278 // control to corresponding JRT methods of SharedRuntime
279
280 void OptoRuntime::slow_arraycopy_C(oopDesc* src, jint src_pos,
281 oopDesc* dest, jint dest_pos,
282 jint length, JavaThread* thread) {
283 SharedRuntime::slow_arraycopy_C(src, src_pos, dest, dest_pos, length, thread);
284 }
285
286 void OptoRuntime::complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current) {
287 SharedRuntime::complete_monitor_locking_C(obj, lock, current);
288 }
289
290
291 //=============================================================================
292 // Opto compiler runtime routines
293 //=============================================================================
294
295
296 //=============================allocation======================================
297 // We failed the fast-path allocation. Now we need to do a scavenge or GC
298 // and try allocation again.
299
300 // object allocation
301 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, JavaThread* current))
302 JRT_BLOCK;
303 #ifndef PRODUCT
304 SharedRuntime::_new_instance_ctr++; // new instance requires GC
305 #endif
306 assert(check_compiled_frame(current), "incorrect caller");
307
308 // These checks are cheap to make and support reflective allocation.
309 int lh = klass->layout_helper();
310 if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
311 Handle holder(current, klass->klass_holder()); // keep the klass alive
312 klass->check_valid_for_instantiation(false, THREAD);
313 if (!HAS_PENDING_EXCEPTION) {
314 InstanceKlass::cast(klass)->initialize(THREAD);
315 }
316 }
317
318 if (!HAS_PENDING_EXCEPTION) {
319 // Scavenge and allocate an instance.
320 Handle holder(current, klass->klass_holder()); // keep the klass alive
321 oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
322 current->set_vm_result_oop(result);
323
324 // Pass oops back through thread local storage. Our apparent type to Java
325 // is that we return an oop, but we can block on exit from this routine and
326 // a GC can trash the oop in C's return register. The generated stub will
327 // fetch the oop from TLS after any possible GC.
328 }
329
330 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
331 JRT_BLOCK_END;
332
333 // inform GC that we won't do card marks for initializing writes.
334 SharedRuntime::on_slowpath_allocation_exit(current);
335 JRT_END
336
337
338 // array allocation
339 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread* current))
340 JRT_BLOCK;
341 #ifndef PRODUCT
342 SharedRuntime::_new_array_ctr++; // new array requires GC
343 #endif
344 assert(check_compiled_frame(current), "incorrect caller");
345
346 // Scavenge and allocate an instance.
347 oop result;
348
349 if (array_type->is_typeArray_klass()) {
350 // The oopFactory likes to work with the element type.
351 // (We could bypass the oopFactory, since it doesn't add much value.)
352 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
353 result = oopFactory::new_typeArray(elem_type, len, THREAD);
354 } else {
355 // Although the oopFactory likes to work with the elem_type,
356 // the compiler prefers the array_type, since it must already have
357 // that latter value in hand for the fast path.
358 Handle holder(current, array_type->klass_holder()); // keep the array klass alive
359 Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass();
360 result = oopFactory::new_objArray(elem_type, len, THREAD);
361 }
362
363 // Pass oops back through thread local storage. Our apparent type to Java
364 // is that we return an oop, but we can block on exit from this routine and
365 // a GC can trash the oop in C's return register. The generated stub will
366 // fetch the oop from TLS after any possible GC.
367 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
368 current->set_vm_result_oop(result);
369 JRT_BLOCK_END;
370
371 // inform GC that we won't do card marks for initializing writes.
372 SharedRuntime::on_slowpath_allocation_exit(current);
373 JRT_END
374
375 // array allocation without zeroing
376 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread* current))
377 JRT_BLOCK;
378 #ifndef PRODUCT
379 SharedRuntime::_new_array_ctr++; // new array requires GC
380 #endif
381 assert(check_compiled_frame(current), "incorrect caller");
382
383 // Scavenge and allocate an instance.
384 oop result;
385
386 assert(array_type->is_typeArray_klass(), "should be called only for type array");
387 // The oopFactory likes to work with the element type.
388 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
389 result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD);
390
391 // Pass oops back through thread local storage. Our apparent type to Java
392 // is that we return an oop, but we can block on exit from this routine and
393 // a GC can trash the oop in C's return register. The generated stub will
394 // fetch the oop from TLS after any possible GC.
395 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
396 current->set_vm_result_oop(result);
408 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
409 size_t hs_bytes = arrayOopDesc::base_offset_in_bytes(elem_type);
410 assert(is_aligned(hs_bytes, BytesPerInt), "must be 4 byte aligned");
411 HeapWord* obj = cast_from_oop<HeapWord*>(result);
412 if (!is_aligned(hs_bytes, BytesPerLong)) {
413 *reinterpret_cast<jint*>(reinterpret_cast<char*>(obj) + hs_bytes) = 0;
414 hs_bytes += BytesPerInt;
415 }
416
417 // Optimized zeroing.
418 assert(is_aligned(hs_bytes, BytesPerLong), "must be 8-byte aligned");
419 const size_t aligned_hs = hs_bytes / BytesPerLong;
420 Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs);
421 }
422
423 JRT_END
424
425 // Note: multianewarray for one dimension is handled inline by GraphKit::new_array.
426
427 // multianewarray for 2 dimensions
428 JRT_ENTRY(void, OptoRuntime::multianewarray2_C(Klass* elem_type, int len1, int len2, JavaThread* current))
429 #ifndef PRODUCT
430 SharedRuntime::_multi2_ctr++; // multianewarray for 1 dimension
431 #endif
432 assert(check_compiled_frame(current), "incorrect caller");
433 assert(elem_type->is_klass(), "not a class");
434 jint dims[2];
435 dims[0] = len1;
436 dims[1] = len2;
437 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
438 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD);
439 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
440 current->set_vm_result_oop(obj);
441 JRT_END
442
443 // multianewarray for 3 dimensions
444 JRT_ENTRY(void, OptoRuntime::multianewarray3_C(Klass* elem_type, int len1, int len2, int len3, JavaThread* current))
445 #ifndef PRODUCT
446 SharedRuntime::_multi3_ctr++; // multianewarray for 1 dimension
447 #endif
448 assert(check_compiled_frame(current), "incorrect caller");
449 assert(elem_type->is_klass(), "not a class");
450 jint dims[3];
451 dims[0] = len1;
452 dims[1] = len2;
453 dims[2] = len3;
454 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
455 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD);
456 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
457 current->set_vm_result_oop(obj);
458 JRT_END
459
460 // multianewarray for 4 dimensions
461 JRT_ENTRY(void, OptoRuntime::multianewarray4_C(Klass* elem_type, int len1, int len2, int len3, int len4, JavaThread* current))
462 #ifndef PRODUCT
463 SharedRuntime::_multi4_ctr++; // multianewarray for 1 dimension
464 #endif
465 assert(check_compiled_frame(current), "incorrect caller");
466 assert(elem_type->is_klass(), "not a class");
467 jint dims[4];
468 dims[0] = len1;
469 dims[1] = len2;
470 dims[2] = len3;
471 dims[3] = len4;
472 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
473 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD);
474 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
475 current->set_vm_result_oop(obj);
476 JRT_END
477
478 // multianewarray for 5 dimensions
479 JRT_ENTRY(void, OptoRuntime::multianewarray5_C(Klass* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread* current))
480 #ifndef PRODUCT
481 SharedRuntime::_multi5_ctr++; // multianewarray for 1 dimension
482 #endif
483 assert(check_compiled_frame(current), "incorrect caller");
484 assert(elem_type->is_klass(), "not a class");
485 jint dims[5];
486 dims[0] = len1;
487 dims[1] = len2;
488 dims[2] = len3;
489 dims[3] = len4;
490 dims[4] = len5;
491 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
492 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD);
493 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
494 current->set_vm_result_oop(obj);
495 JRT_END
496
497 JRT_ENTRY(void, OptoRuntime::multianewarrayN_C(Klass* elem_type, arrayOopDesc* dims, JavaThread* current))
498 assert(check_compiled_frame(current), "incorrect caller");
499 assert(elem_type->is_klass(), "not a class");
500 assert(oop(dims)->is_typeArray(), "not an array");
501
502 ResourceMark rm;
503 jint len = dims->length();
504 assert(len > 0, "Dimensions array should contain data");
505 jint *c_dims = NEW_RESOURCE_ARRAY(jint, len);
506 ArrayAccess<>::arraycopy_to_native<>(dims, typeArrayOopDesc::element_offset<jint>(0),
507 c_dims, len);
508
509 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
510 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(len, c_dims, THREAD);
511 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
512 current->set_vm_result_oop(obj);
513 JRT_END
514
515 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notify_C(oopDesc* obj, JavaThread* current))
516
517 // Very few notify/notifyAll operations find any threads on the waitset, so
518 // the dominant fast-path is to simply return.
519 // Relatedly, it's critical that notify/notifyAll be fast in order to
520 // reduce lock hold times.
521 if (!SafepointSynchronize::is_synchronizing()) {
522 if (ObjectSynchronizer::quick_notify(obj, current, false)) {
523 return;
524 }
525 }
526
527 // This is the case the fast-path above isn't provisioned to handle.
528 // The fast-path is designed to handle frequently arising cases in an efficient manner.
529 // (The fast-path is just a degenerate variant of the slow-path).
530 // Perform the dreaded state transition and pass control into the slow-path.
531 JRT_BLOCK;
532 Handle h_obj(current, obj);
533 ObjectSynchronizer::notify(h_obj, CHECK);
534 JRT_BLOCK_END;
535 JRT_END
536
537 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notifyAll_C(oopDesc* obj, JavaThread* current))
538
539 if (!SafepointSynchronize::is_synchronizing() ) {
540 if (ObjectSynchronizer::quick_notify(obj, current, true)) {
541 return;
542 }
543 }
544
545 // This is the case the fast-path above isn't provisioned to handle.
546 // The fast-path is designed to handle frequently arising cases in an efficient manner.
547 // (The fast-path is just a degenerate variant of the slow-path).
548 // Perform the dreaded state transition and pass control into the slow-path.
549 JRT_BLOCK;
550 Handle h_obj(current, obj);
551 ObjectSynchronizer::notifyall(h_obj, CHECK);
552 JRT_BLOCK_END;
553 JRT_END
554
555 JRT_ENTRY(void, OptoRuntime::vthread_end_first_transition_C(oopDesc* vt, jboolean is_mount, JavaThread* current))
556 MountUnmountDisabler::end_transition(current, vt, true /*is_mount*/, true /*is_thread_start*/);
557 JRT_END
660 fields = TypeTuple::fields(1);
661 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
662 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
663
664 return TypeFunc::make(domain, range);
665 }
666
667 static const TypeFunc* make_uncommon_trap_Type() {
668 // create input type (domain)
669 const Type **fields = TypeTuple::fields(1);
670 fields[TypeFunc::Parms+0] = TypeInt::INT; // trap_reason (deopt reason and action)
671 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
672
673 // create result type (range)
674 fields = TypeTuple::fields(0);
675 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
676
677 return TypeFunc::make(domain, range);
678 }
679
680 //-----------------------------------------------------------------------------
681 // Monitor Handling
682
683 static const TypeFunc* make_complete_monitor_enter_Type() {
684 // create input type (domain)
685 const Type **fields = TypeTuple::fields(2);
686 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
687 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock
688 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
689
690 // create result type (range)
691 fields = TypeTuple::fields(0);
692
693 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
694
695 return TypeFunc::make(domain,range);
696 }
697
698 //-----------------------------------------------------------------------------
699
1842 assert(reg >= 0 && reg < _last_Mach_Reg, "must be a machine register");
1843 switch (register_save_policy[reg]) {
1844 case 'C': return false; //SOC
1845 case 'E': return true ; //SOE
1846 case 'N': return false; //NS
1847 case 'A': return false; //AS
1848 }
1849 ShouldNotReachHere();
1850 return false;
1851 }
1852
1853 //-----------------------------------------------------------------------
1854 // Exceptions
1855 //
1856
1857 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg);
1858
1859 // The method is an entry that is always called by a C++ method not
1860 // directly from compiled code. Compiled code will call the C++ method following.
1861 // We can't allow async exception to be installed during exception processing.
1862 JRT_ENTRY_NO_ASYNC(address, OptoRuntime::handle_exception_C_helper(JavaThread* current, nmethod* &nm))
1863 // The frame we rethrow the exception to might not have been processed by the GC yet.
1864 // The stack watermark barrier takes care of detecting that and ensuring the frame
1865 // has updated oops.
1866 StackWatermarkSet::after_unwind(current);
1867
1868 MACOS_AARCH64_ONLY(os::thread_wx_enable_write());
1869
1870 // Do not confuse exception_oop with pending_exception. The exception_oop
1871 // is only used to pass arguments into the method. Not for general
1872 // exception handling. DO NOT CHANGE IT to use pending_exception, since
1873 // the runtime stubs checks this on exit.
1874 assert(current->exception_oop() != nullptr, "exception oop is found");
1875 address handler_address = nullptr;
1876
1877 Handle exception(current, current->exception_oop());
1878 address pc = current->exception_pc();
1879
1880 // Clear out the exception oop and pc since looking up an
1881 // exception handler can cause class loading, which might throw an
1882 // exception and those fields are expected to be clear during
2114 frame caller_frame = stub_frame.sender(®_map);
2115 return caller_frame.is_deoptimized_frame();
2116 }
2117
2118 static const TypeFunc* make_register_finalizer_Type() {
2119 // create input type (domain)
2120 const Type **fields = TypeTuple::fields(1);
2121 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver
2122 // // The JavaThread* is passed to each routine as the last argument
2123 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
2124 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
2125
2126 // create result type (range)
2127 fields = TypeTuple::fields(0);
2128
2129 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2130
2131 return TypeFunc::make(domain,range);
2132 }
2133
2134 #if INCLUDE_JFR
2135 static const TypeFunc* make_class_id_load_barrier_Type() {
2136 // create input type (domain)
2137 const Type **fields = TypeTuple::fields(1);
2138 fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS;
2139 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields);
2140
2141 // create result type (range)
2142 fields = TypeTuple::fields(0);
2143
2144 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields);
2145
2146 return TypeFunc::make(domain,range);
2147 }
2148 #endif // INCLUDE_JFR
2149
2150 //-----------------------------------------------------------------------------
2151 static const TypeFunc* make_dtrace_method_entry_exit_Type() {
2152 // create input type (domain)
2153 const Type **fields = TypeTuple::fields(2);
2154 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2155 fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM; // Method*; Method we are entering
2156 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2157
2158 // create result type (range)
2159 fields = TypeTuple::fields(0);
2160
2161 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2162
2163 return TypeFunc::make(domain,range);
2164 }
2165
2166 static const TypeFunc* make_dtrace_object_alloc_Type() {
2167 // create input type (domain)
2168 const Type **fields = TypeTuple::fields(2);
2169 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2170 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object
2171
2172 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2173
2174 // create result type (range)
2175 fields = TypeTuple::fields(0);
2176
2177 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2178
2179 return TypeFunc::make(domain,range);
2180 }
2181
2182 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer_C(oopDesc* obj, JavaThread* current))
2183 assert(oopDesc::is_oop(obj), "must be a valid oop");
2184 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
2185 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
2186 JRT_END
2187
2188 //-----------------------------------------------------------------------------
2189
2190 NamedCounter * volatile OptoRuntime::_named_counters = nullptr;
2191
2192 //
2193 // dump the collected NamedCounters.
2194 //
2195 void OptoRuntime::print_named_counters() {
2196 int total_lock_count = 0;
2197 int eliminated_lock_count = 0;
2198
2199 NamedCounter* c = _named_counters;
2200 while (c) {
2201 if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) {
2202 int count = c->count();
2203 if (count > 0) {
2204 bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter;
2205 if (Verbose) {
2206 tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : "");
2207 }
2273 _multianewarray5_Type = multianewarray_Type(5);
2274 _multianewarrayN_Type = make_multianewarrayN_Type();
2275 _complete_monitor_enter_Type = make_complete_monitor_enter_Type();
2276 _complete_monitor_exit_Type = make_complete_monitor_exit_Type();
2277 _monitor_notify_Type = make_monitor_notify_Type();
2278 _uncommon_trap_Type = make_uncommon_trap_Type();
2279 _athrow_Type = make_athrow_Type();
2280 _rethrow_Type = make_rethrow_Type();
2281 _Math_D_D_Type = make_Math_D_D_Type();
2282 _Math_DD_D_Type = make_Math_DD_D_Type();
2283 _modf_Type = make_modf_Type();
2284 _l2f_Type = make_l2f_Type();
2285 _void_long_Type = make_void_long_Type();
2286 _void_void_Type = make_void_void_Type();
2287 _jfr_write_checkpoint_Type = make_jfr_write_checkpoint_Type();
2288 _flush_windows_Type = make_flush_windows_Type();
2289 _fast_arraycopy_Type = make_arraycopy_Type(ac_fast);
2290 _checkcast_arraycopy_Type = make_arraycopy_Type(ac_checkcast);
2291 _generic_arraycopy_Type = make_arraycopy_Type(ac_generic);
2292 _slow_arraycopy_Type = make_arraycopy_Type(ac_slow);
2293 _unsafe_setmemory_Type = make_setmemory_Type();
2294 _array_fill_Type = make_array_fill_Type();
2295 _array_sort_Type = make_array_sort_Type();
2296 _array_partition_Type = make_array_partition_Type();
2297 _aescrypt_block_Type = make_aescrypt_block_Type();
2298 _cipherBlockChaining_aescrypt_Type = make_cipherBlockChaining_aescrypt_Type();
2299 _electronicCodeBook_aescrypt_Type = make_electronicCodeBook_aescrypt_Type();
2300 _counterMode_aescrypt_Type = make_counterMode_aescrypt_Type();
2301 _galoisCounterMode_aescrypt_Type = make_galoisCounterMode_aescrypt_Type();
2302 _digestBase_implCompress_with_sha3_Type = make_digestBase_implCompress_Type( /* is_sha3= */ true);
2303 _digestBase_implCompress_without_sha3_Type = make_digestBase_implCompress_Type( /* is_sha3= */ false);;
2304 _digestBase_implCompressMB_with_sha3_Type = make_digestBase_implCompressMB_Type(/* is_sha3= */ true);
2305 _digestBase_implCompressMB_without_sha3_Type = make_digestBase_implCompressMB_Type(/* is_sha3= */ false);
2306 _double_keccak_Type = make_double_keccak_Type();
2307 _multiplyToLen_Type = make_multiplyToLen_Type();
2308 _montgomeryMultiply_Type = make_montgomeryMultiply_Type();
2309 _montgomerySquare_Type = make_montgomerySquare_Type();
2310 _squareToLen_Type = make_squareToLen_Type();
2311 _mulAdd_Type = make_mulAdd_Type();
2312 _bigIntegerShift_Type = make_bigIntegerShift_Type();
2348 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
2349 trace_exception_counter++;
2350 stringStream tempst;
2351
2352 tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
2353 exception_oop->print_value_on(&tempst);
2354 tempst.print(" in ");
2355 CodeBlob* blob = CodeCache::find_blob(exception_pc);
2356 if (blob->is_nmethod()) {
2357 blob->as_nmethod()->method()->print_value_on(&tempst);
2358 } else if (blob->is_runtime_stub()) {
2359 tempst.print("<runtime-stub>");
2360 } else {
2361 tempst.print("<unknown>");
2362 }
2363 tempst.print(" at " INTPTR_FORMAT, p2i(exception_pc));
2364 tempst.print("]");
2365
2366 st->print_raw_cr(tempst.freeze());
2367 }
|
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 */
24
25 #include "classfile/vmClasses.hpp"
26 #include "classfile/vmSymbols.hpp"
27 #include "code/aotCodeCache.hpp"
28 #include "code/codeCache.hpp"
29 #include "code/compiledIC.hpp"
30 #include "code/nmethod.hpp"
31 #include "code/pcDesc.hpp"
32 #include "code/scopeDesc.hpp"
33 #include "code/vtableStubs.hpp"
34 #include "compiler/compilationMemoryStatistic.hpp"
35 #include "compiler/compileBroker.hpp"
36 #include "compiler/compilerDefinitions.inline.hpp"
37 #include "compiler/oopMap.hpp"
38 #include "gc/g1/g1HeapRegion.hpp"
39 #include "gc/shared/barrierSet.hpp"
40 #include "gc/shared/collectedHeap.hpp"
41 #include "gc/shared/gcLocker.hpp"
42 #include "interpreter/bytecode.hpp"
43 #include "interpreter/interpreter.hpp"
44 #include "interpreter/linkResolver.hpp"
45 #include "logging/log.hpp"
46 #include "logging/logStream.hpp"
47 #include "memory/oopFactory.hpp"
48 #include "memory/resourceArea.hpp"
49 #include "oops/klass.inline.hpp"
50 #include "oops/objArrayKlass.hpp"
51 #include "oops/oop.inline.hpp"
52 #include "oops/typeArrayOop.inline.hpp"
53 #include "opto/ad.hpp"
54 #include "opto/addnode.hpp"
55 #include "opto/callnode.hpp"
56 #include "opto/cfgnode.hpp"
57 #include "opto/graphKit.hpp"
58 #include "opto/machnode.hpp"
59 #include "opto/matcher.hpp"
60 #include "opto/memnode.hpp"
61 #include "opto/mulnode.hpp"
62 #include "opto/output.hpp"
63 #include "opto/runtime.hpp"
64 #include "opto/subnode.hpp"
65 #include "prims/jvmtiExport.hpp"
66 #include "runtime/atomicAccess.hpp"
67 #include "runtime/frame.inline.hpp"
68 #include "runtime/handles.inline.hpp"
69 #include "runtime/interfaceSupport.inline.hpp"
70 #include "runtime/java.hpp"
71 #include "runtime/javaCalls.hpp"
72 #include "runtime/mountUnmountDisabler.hpp"
73 #include "runtime/perfData.inline.hpp"
74 #include "runtime/sharedRuntime.hpp"
75 #include "runtime/signature.hpp"
76 #include "runtime/stackWatermarkSet.hpp"
77 #include "runtime/synchronizer.hpp"
78 #include "runtime/threadWXSetters.inline.hpp"
79 #include "runtime/vframe.hpp"
80 #include "runtime/vframe_hp.hpp"
81 #include "runtime/vframeArray.hpp"
82 #include "services/management.hpp"
83 #include "utilities/copy.hpp"
84 #include "utilities/preserveException.hpp"
85
86
87 // For debugging purposes:
88 // To force FullGCALot inside a runtime function, add the following two lines
89 //
90 // Universe::release_fullgc_alot_dummy();
91 // Universe::heap()->collect();
92 //
93 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
94
95
96 #define C2_BLOB_FIELD_DEFINE(name, type) \
97 type* OptoRuntime:: BLOB_FIELD_NAME(name) = nullptr;
98 #define C2_STUB_FIELD_NAME(name) _ ## name ## _Java
99 #define C2_STUB_FIELD_DEFINE(name, f, t, r) \
100 address OptoRuntime:: C2_STUB_FIELD_NAME(name) = nullptr;
101 C2_STUBS_DO(C2_BLOB_FIELD_DEFINE, C2_STUB_FIELD_DEFINE)
102 #undef C2_BLOB_FIELD_DEFINE
103 #undef C2_STUB_FIELD_DEFINE
104
105 address OptoRuntime::_vtable_must_compile_Java = nullptr;
106
107 PerfCounter* _perf_OptoRuntime_class_init_barrier_redundant_count = nullptr;
108
109 // This should be called in an assertion at the start of OptoRuntime routines
110 // which are entered from compiled code (all of them)
111 #ifdef ASSERT
112 static bool check_compiled_frame(JavaThread* thread) {
113 assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
114 RegisterMap map(thread,
115 RegisterMap::UpdateMap::skip,
116 RegisterMap::ProcessFrames::include,
117 RegisterMap::WalkContinuation::skip);
118 frame caller = thread->last_frame().sender(&map);
119 assert(caller.is_compiled_frame(), "not being called from compiled like code");
120 return true;
121 }
122 #endif // ASSERT
123
124 /*
125 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, return_pc) \
126 var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, return_pc); \
127 if (var == nullptr) { return false; }
128 */
144 // from the stub name by appending suffix '_C'. However, in two cases
145 // a common target method also needs to be called from shared runtime
146 // stubs. In these two cases the opto stubs rely on method
147 // imlementations defined in class SharedRuntime. The following
148 // defines temporarily rebind the generated names to reference the
149 // relevant implementations.
150
151 #define GEN_C2_STUB(name, fancy_jump, pass_tls, pass_retpc ) \
152 C2_STUB_FIELD_NAME(name) = \
153 generate_stub(env, \
154 C2_STUB_TYPEFUNC(name), \
155 C2_STUB_C_FUNC(name), \
156 C2_STUB_NAME(name), \
157 C2_STUB_ID(name), \
158 fancy_jump, \
159 pass_tls, \
160 pass_retpc); \
161 if (C2_STUB_FIELD_NAME(name) == nullptr) { return false; } \
162
163 bool OptoRuntime::generate(ciEnv* env) {
164 init_counters();
165
166 C2_STUBS_DO(GEN_C2_BLOB, GEN_C2_STUB)
167
168 return true;
169 }
170
171 #undef GEN_C2_BLOB
172
173 #undef C2_STUB_FIELD_NAME
174 #undef C2_STUB_TYPEFUNC
175 #undef C2_STUB_C_FUNC
176 #undef C2_STUB_NAME
177 #undef GEN_C2_STUB
178
179 // #undef gen
180
181 const TypeFunc* OptoRuntime::_new_instance_Type = nullptr;
182 const TypeFunc* OptoRuntime::_new_array_Type = nullptr;
183 const TypeFunc* OptoRuntime::_multianewarray2_Type = nullptr;
184 const TypeFunc* OptoRuntime::_multianewarray3_Type = nullptr;
186 const TypeFunc* OptoRuntime::_multianewarray5_Type = nullptr;
187 const TypeFunc* OptoRuntime::_multianewarrayN_Type = nullptr;
188 const TypeFunc* OptoRuntime::_complete_monitor_enter_Type = nullptr;
189 const TypeFunc* OptoRuntime::_complete_monitor_exit_Type = nullptr;
190 const TypeFunc* OptoRuntime::_monitor_notify_Type = nullptr;
191 const TypeFunc* OptoRuntime::_uncommon_trap_Type = nullptr;
192 const TypeFunc* OptoRuntime::_athrow_Type = nullptr;
193 const TypeFunc* OptoRuntime::_rethrow_Type = nullptr;
194 const TypeFunc* OptoRuntime::_Math_D_D_Type = nullptr;
195 const TypeFunc* OptoRuntime::_Math_DD_D_Type = nullptr;
196 const TypeFunc* OptoRuntime::_modf_Type = nullptr;
197 const TypeFunc* OptoRuntime::_l2f_Type = nullptr;
198 const TypeFunc* OptoRuntime::_void_long_Type = nullptr;
199 const TypeFunc* OptoRuntime::_void_void_Type = nullptr;
200 const TypeFunc* OptoRuntime::_jfr_write_checkpoint_Type = nullptr;
201 const TypeFunc* OptoRuntime::_flush_windows_Type = nullptr;
202 const TypeFunc* OptoRuntime::_fast_arraycopy_Type = nullptr;
203 const TypeFunc* OptoRuntime::_checkcast_arraycopy_Type = nullptr;
204 const TypeFunc* OptoRuntime::_generic_arraycopy_Type = nullptr;
205 const TypeFunc* OptoRuntime::_slow_arraycopy_Type = nullptr;
206 const TypeFunc* OptoRuntime::_compile_method_Type = nullptr;
207 const TypeFunc* OptoRuntime::_unsafe_setmemory_Type = nullptr;
208 const TypeFunc* OptoRuntime::_array_fill_Type = nullptr;
209 const TypeFunc* OptoRuntime::_array_sort_Type = nullptr;
210 const TypeFunc* OptoRuntime::_array_partition_Type = nullptr;
211 const TypeFunc* OptoRuntime::_aescrypt_block_Type = nullptr;
212 const TypeFunc* OptoRuntime::_cipherBlockChaining_aescrypt_Type = nullptr;
213 const TypeFunc* OptoRuntime::_electronicCodeBook_aescrypt_Type = nullptr;
214 const TypeFunc* OptoRuntime::_counterMode_aescrypt_Type = nullptr;
215 const TypeFunc* OptoRuntime::_galoisCounterMode_aescrypt_Type = nullptr;
216 const TypeFunc* OptoRuntime::_digestBase_implCompress_with_sha3_Type = nullptr;
217 const TypeFunc* OptoRuntime::_digestBase_implCompress_without_sha3_Type = nullptr;
218 const TypeFunc* OptoRuntime::_digestBase_implCompressMB_with_sha3_Type = nullptr;
219 const TypeFunc* OptoRuntime::_digestBase_implCompressMB_without_sha3_Type = nullptr;
220 const TypeFunc* OptoRuntime::_double_keccak_Type = nullptr;
221 const TypeFunc* OptoRuntime::_multiplyToLen_Type = nullptr;
222 const TypeFunc* OptoRuntime::_montgomeryMultiply_Type = nullptr;
223 const TypeFunc* OptoRuntime::_montgomerySquare_Type = nullptr;
224 const TypeFunc* OptoRuntime::_squareToLen_Type = nullptr;
225 const TypeFunc* OptoRuntime::_mulAdd_Type = nullptr;
226 const TypeFunc* OptoRuntime::_bigIntegerShift_Type = nullptr;
248 const TypeFunc* OptoRuntime::_updateBytesCRC32_Type = nullptr;
249 const TypeFunc* OptoRuntime::_updateBytesCRC32C_Type = nullptr;
250 const TypeFunc* OptoRuntime::_updateBytesAdler32_Type = nullptr;
251 const TypeFunc* OptoRuntime::_osr_end_Type = nullptr;
252 const TypeFunc* OptoRuntime::_register_finalizer_Type = nullptr;
253 const TypeFunc* OptoRuntime::_vthread_transition_Type = nullptr;
254 #if INCLUDE_JFR
255 const TypeFunc* OptoRuntime::_class_id_load_barrier_Type = nullptr;
256 #endif // INCLUDE_JFR
257 const TypeFunc* OptoRuntime::_dtrace_method_entry_exit_Type = nullptr;
258 const TypeFunc* OptoRuntime::_dtrace_object_alloc_Type = nullptr;
259
260 // Helper method to do generation of RunTimeStub's
261 address OptoRuntime::generate_stub(ciEnv* env,
262 TypeFunc_generator gen, address C_function,
263 const char *name, StubId stub_id,
264 int is_fancy_jump, bool pass_tls,
265 bool return_pc) {
266
267 // Matching the default directive, we currently have no method to match.
268 DirectiveSet* directive = DirectivesStack::getDefaultDirective(CompilerThread::current()->compiler());
269 CompilationMemoryStatisticMark cmsm(directive);
270 ResourceMark rm;
271 Compile C(env, gen, C_function, name, stub_id, is_fancy_jump, pass_tls, return_pc, directive);
272 DirectivesStack::release(directive);
273 return C.stub_entry_point();
274 }
275
276 const char* OptoRuntime::stub_name(address entry) {
277 #ifndef PRODUCT
278 CodeBlob* cb = CodeCache::find_blob(entry);
279 RuntimeStub* rs =(RuntimeStub *)cb;
280 assert(rs != nullptr && rs->is_runtime_stub(), "not a runtime stub");
281 return rs->name();
282 #else
283 // Fast implementation for product mode (maybe it should be inlined too)
284 return "runtime stub";
285 #endif
286 }
287
288 // local methods passed as arguments to stub generator that forward
289 // control to corresponding JRT methods of SharedRuntime
290
291 void OptoRuntime::slow_arraycopy_C(oopDesc* src, jint src_pos,
292 oopDesc* dest, jint dest_pos,
293 jint length, JavaThread* thread) {
294 SharedRuntime::slow_arraycopy_C(src, src_pos, dest, dest_pos, length, thread);
295 }
296
297 void OptoRuntime::complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current) {
298 SharedRuntime::complete_monitor_locking_C(obj, lock, current);
299 }
300
301 JRT_ENTRY(void, OptoRuntime::compile_method_C(Method* method, JavaThread* current))
302 methodHandle m(current, method);
303 CompLevel level = CompLevel_full_optimization;
304 bool jit_compilation = true;
305 CompileBroker::compile_method(m, InvocationEntryBci, level, 0, jit_compilation, CompileTask::Reason_MustBeCompiled, current);
306 if (HAS_PENDING_EXCEPTION) {
307 CLEAR_PENDING_EXCEPTION;
308 }
309 JRT_END
310
311 //=============================================================================
312 // Opto compiler runtime routines
313 //=============================================================================
314
315
316 //=============================allocation======================================
317 // We failed the fast-path allocation. Now we need to do a scavenge or GC
318 // and try allocation again.
319
320 // object allocation
321 JRT_BLOCK_ENTRY_PROF(void, OptoRuntime, new_instance_C, OptoRuntime::new_instance_C(Klass* klass, JavaThread* current))
322 JRT_BLOCK;
323 #ifndef PRODUCT
324 SharedRuntime::_new_instance_ctr++; // new instance requires GC
325 #endif
326 assert(check_compiled_frame(current), "incorrect caller");
327
328 // These checks are cheap to make and support reflective allocation.
329 int lh = klass->layout_helper();
330 if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
331 Handle holder(current, klass->klass_holder()); // keep the klass alive
332 klass->check_valid_for_instantiation(false, THREAD);
333 if (!HAS_PENDING_EXCEPTION) {
334 InstanceKlass::cast(klass)->initialize(THREAD);
335 }
336 }
337
338 if (!HAS_PENDING_EXCEPTION) {
339 // Scavenge and allocate an instance.
340 Handle holder(current, klass->klass_holder()); // keep the klass alive
341 oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
342 current->set_vm_result_oop(result);
343
344 // Pass oops back through thread local storage. Our apparent type to Java
345 // is that we return an oop, but we can block on exit from this routine and
346 // a GC can trash the oop in C's return register. The generated stub will
347 // fetch the oop from TLS after any possible GC.
348 }
349
350 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
351 JRT_BLOCK_END;
352
353 // inform GC that we won't do card marks for initializing writes.
354 SharedRuntime::on_slowpath_allocation_exit(current);
355 JRT_END
356
357
358 // array allocation
359 JRT_BLOCK_ENTRY_PROF(void, OptoRuntime, new_array_C, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread* current))
360 JRT_BLOCK;
361 #ifndef PRODUCT
362 SharedRuntime::_new_array_ctr++; // new array requires GC
363 #endif
364 assert(check_compiled_frame(current), "incorrect caller");
365
366 // Scavenge and allocate an instance.
367 oop result;
368
369 if (array_type->is_typeArray_klass()) {
370 // The oopFactory likes to work with the element type.
371 // (We could bypass the oopFactory, since it doesn't add much value.)
372 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
373 result = oopFactory::new_typeArray(elem_type, len, THREAD);
374 } else {
375 // Although the oopFactory likes to work with the elem_type,
376 // the compiler prefers the array_type, since it must already have
377 // that latter value in hand for the fast path.
378 Handle holder(current, array_type->klass_holder()); // keep the array klass alive
379 Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass();
380 result = oopFactory::new_objArray(elem_type, len, THREAD);
381 }
382
383 // Pass oops back through thread local storage. Our apparent type to Java
384 // is that we return an oop, but we can block on exit from this routine and
385 // a GC can trash the oop in C's return register. The generated stub will
386 // fetch the oop from TLS after any possible GC.
387 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
388 current->set_vm_result_oop(result);
389 JRT_BLOCK_END;
390
391 // inform GC that we won't do card marks for initializing writes.
392 SharedRuntime::on_slowpath_allocation_exit(current);
393 JRT_END
394
395 // array allocation without zeroing
396 JRT_BLOCK_ENTRY_PROF(void, OptoRuntime, new_array_nozero_C, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread* current))
397 JRT_BLOCK;
398 #ifndef PRODUCT
399 SharedRuntime::_new_array_ctr++; // new array requires GC
400 #endif
401 assert(check_compiled_frame(current), "incorrect caller");
402
403 // Scavenge and allocate an instance.
404 oop result;
405
406 assert(array_type->is_typeArray_klass(), "should be called only for type array");
407 // The oopFactory likes to work with the element type.
408 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
409 result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD);
410
411 // Pass oops back through thread local storage. Our apparent type to Java
412 // is that we return an oop, but we can block on exit from this routine and
413 // a GC can trash the oop in C's return register. The generated stub will
414 // fetch the oop from TLS after any possible GC.
415 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
416 current->set_vm_result_oop(result);
428 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
429 size_t hs_bytes = arrayOopDesc::base_offset_in_bytes(elem_type);
430 assert(is_aligned(hs_bytes, BytesPerInt), "must be 4 byte aligned");
431 HeapWord* obj = cast_from_oop<HeapWord*>(result);
432 if (!is_aligned(hs_bytes, BytesPerLong)) {
433 *reinterpret_cast<jint*>(reinterpret_cast<char*>(obj) + hs_bytes) = 0;
434 hs_bytes += BytesPerInt;
435 }
436
437 // Optimized zeroing.
438 assert(is_aligned(hs_bytes, BytesPerLong), "must be 8-byte aligned");
439 const size_t aligned_hs = hs_bytes / BytesPerLong;
440 Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs);
441 }
442
443 JRT_END
444
445 // Note: multianewarray for one dimension is handled inline by GraphKit::new_array.
446
447 // multianewarray for 2 dimensions
448 JRT_ENTRY_PROF(void, OptoRuntime, multianewarray2_C, OptoRuntime::multianewarray2_C(Klass* elem_type, int len1, int len2, JavaThread* current))
449 #ifndef PRODUCT
450 SharedRuntime::_multi2_ctr++; // multianewarray for 1 dimension
451 #endif
452 assert(check_compiled_frame(current), "incorrect caller");
453 assert(elem_type->is_klass(), "not a class");
454 jint dims[2];
455 dims[0] = len1;
456 dims[1] = len2;
457 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
458 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD);
459 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
460 current->set_vm_result_oop(obj);
461 JRT_END
462
463 // multianewarray for 3 dimensions
464 JRT_ENTRY_PROF(void, OptoRuntime, multianewarray3_C, OptoRuntime::multianewarray3_C(Klass* elem_type, int len1, int len2, int len3, JavaThread* current))
465 #ifndef PRODUCT
466 SharedRuntime::_multi3_ctr++; // multianewarray for 1 dimension
467 #endif
468 assert(check_compiled_frame(current), "incorrect caller");
469 assert(elem_type->is_klass(), "not a class");
470 jint dims[3];
471 dims[0] = len1;
472 dims[1] = len2;
473 dims[2] = len3;
474 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
475 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD);
476 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
477 current->set_vm_result_oop(obj);
478 JRT_END
479
480 // multianewarray for 4 dimensions
481 JRT_ENTRY_PROF(void, OptoRuntime, multianewarray4_C, OptoRuntime::multianewarray4_C(Klass* elem_type, int len1, int len2, int len3, int len4, JavaThread* current))
482 #ifndef PRODUCT
483 SharedRuntime::_multi4_ctr++; // multianewarray for 1 dimension
484 #endif
485 assert(check_compiled_frame(current), "incorrect caller");
486 assert(elem_type->is_klass(), "not a class");
487 jint dims[4];
488 dims[0] = len1;
489 dims[1] = len2;
490 dims[2] = len3;
491 dims[3] = len4;
492 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
493 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD);
494 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
495 current->set_vm_result_oop(obj);
496 JRT_END
497
498 // multianewarray for 5 dimensions
499 JRT_ENTRY(void, OptoRuntime::multianewarray5_C(Klass* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread* current))
500 #ifndef PRODUCT
501 SharedRuntime::_multi5_ctr++; // multianewarray for 1 dimension
502 #endif
503 assert(check_compiled_frame(current), "incorrect caller");
504 assert(elem_type->is_klass(), "not a class");
505 jint dims[5];
506 dims[0] = len1;
507 dims[1] = len2;
508 dims[2] = len3;
509 dims[3] = len4;
510 dims[4] = len5;
511 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
512 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD);
513 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
514 current->set_vm_result_oop(obj);
515 JRT_END
516
517 JRT_ENTRY_PROF(void, OptoRuntime, multianewarrayN_C, OptoRuntime::multianewarrayN_C(Klass* elem_type, arrayOopDesc* dims, JavaThread* current))
518 assert(check_compiled_frame(current), "incorrect caller");
519 assert(elem_type->is_klass(), "not a class");
520 assert(oop(dims)->is_typeArray(), "not an array");
521
522 ResourceMark rm;
523 jint len = dims->length();
524 assert(len > 0, "Dimensions array should contain data");
525 jint *c_dims = NEW_RESOURCE_ARRAY(jint, len);
526 ArrayAccess<>::arraycopy_to_native<>(dims, typeArrayOopDesc::element_offset<jint>(0),
527 c_dims, len);
528
529 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
530 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(len, c_dims, THREAD);
531 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
532 current->set_vm_result_oop(obj);
533 JRT_END
534
535 JRT_BLOCK_ENTRY_PROF(void, OptoRuntime, monitor_notify_C, OptoRuntime::monitor_notify_C(oopDesc* obj, JavaThread* current))
536
537 // Very few notify/notifyAll operations find any threads on the waitset, so
538 // the dominant fast-path is to simply return.
539 // Relatedly, it's critical that notify/notifyAll be fast in order to
540 // reduce lock hold times.
541 if (!SafepointSynchronize::is_synchronizing()) {
542 if (ObjectSynchronizer::quick_notify(obj, current, false)) {
543 return;
544 }
545 }
546
547 // This is the case the fast-path above isn't provisioned to handle.
548 // The fast-path is designed to handle frequently arising cases in an efficient manner.
549 // (The fast-path is just a degenerate variant of the slow-path).
550 // Perform the dreaded state transition and pass control into the slow-path.
551 JRT_BLOCK;
552 Handle h_obj(current, obj);
553 ObjectSynchronizer::notify(h_obj, CHECK);
554 JRT_BLOCK_END;
555 JRT_END
556
557 JRT_BLOCK_ENTRY_PROF(void, OptoRuntime, monitor_notifyAll_C, OptoRuntime::monitor_notifyAll_C(oopDesc* obj, JavaThread* current))
558
559 if (!SafepointSynchronize::is_synchronizing() ) {
560 if (ObjectSynchronizer::quick_notify(obj, current, true)) {
561 return;
562 }
563 }
564
565 // This is the case the fast-path above isn't provisioned to handle.
566 // The fast-path is designed to handle frequently arising cases in an efficient manner.
567 // (The fast-path is just a degenerate variant of the slow-path).
568 // Perform the dreaded state transition and pass control into the slow-path.
569 JRT_BLOCK;
570 Handle h_obj(current, obj);
571 ObjectSynchronizer::notifyall(h_obj, CHECK);
572 JRT_BLOCK_END;
573 JRT_END
574
575 JRT_ENTRY(void, OptoRuntime::vthread_end_first_transition_C(oopDesc* vt, jboolean is_mount, JavaThread* current))
576 MountUnmountDisabler::end_transition(current, vt, true /*is_mount*/, true /*is_thread_start*/);
577 JRT_END
680 fields = TypeTuple::fields(1);
681 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
682 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
683
684 return TypeFunc::make(domain, range);
685 }
686
687 static const TypeFunc* make_uncommon_trap_Type() {
688 // create input type (domain)
689 const Type **fields = TypeTuple::fields(1);
690 fields[TypeFunc::Parms+0] = TypeInt::INT; // trap_reason (deopt reason and action)
691 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
692
693 // create result type (range)
694 fields = TypeTuple::fields(0);
695 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
696
697 return TypeFunc::make(domain, range);
698 }
699
700 static const TypeFunc* make_compile_method_Type() {
701 // create input type (domain)
702 const Type** fields = TypeTuple::fields(1);
703 fields[TypeFunc::Parms+0] = TypePtr::NOTNULL; // method to be compiled
704 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
705
706 // create result type (range)
707 fields = TypeTuple::fields(0);
708 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+0,fields);
709 return TypeFunc::make(domain, range);
710 }
711
712 //-----------------------------------------------------------------------------
713 // Monitor Handling
714
715 static const TypeFunc* make_complete_monitor_enter_Type() {
716 // create input type (domain)
717 const Type **fields = TypeTuple::fields(2);
718 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
719 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock
720 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
721
722 // create result type (range)
723 fields = TypeTuple::fields(0);
724
725 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
726
727 return TypeFunc::make(domain,range);
728 }
729
730 //-----------------------------------------------------------------------------
731
1874 assert(reg >= 0 && reg < _last_Mach_Reg, "must be a machine register");
1875 switch (register_save_policy[reg]) {
1876 case 'C': return false; //SOC
1877 case 'E': return true ; //SOE
1878 case 'N': return false; //NS
1879 case 'A': return false; //AS
1880 }
1881 ShouldNotReachHere();
1882 return false;
1883 }
1884
1885 //-----------------------------------------------------------------------
1886 // Exceptions
1887 //
1888
1889 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg);
1890
1891 // The method is an entry that is always called by a C++ method not
1892 // directly from compiled code. Compiled code will call the C++ method following.
1893 // We can't allow async exception to be installed during exception processing.
1894 JRT_ENTRY_NO_ASYNC_PROF(address, OptoRuntime, handle_exception_C_helper, OptoRuntime::handle_exception_C_helper(JavaThread* current, nmethod* &nm))
1895 // The frame we rethrow the exception to might not have been processed by the GC yet.
1896 // The stack watermark barrier takes care of detecting that and ensuring the frame
1897 // has updated oops.
1898 StackWatermarkSet::after_unwind(current);
1899
1900 MACOS_AARCH64_ONLY(os::thread_wx_enable_write());
1901
1902 // Do not confuse exception_oop with pending_exception. The exception_oop
1903 // is only used to pass arguments into the method. Not for general
1904 // exception handling. DO NOT CHANGE IT to use pending_exception, since
1905 // the runtime stubs checks this on exit.
1906 assert(current->exception_oop() != nullptr, "exception oop is found");
1907 address handler_address = nullptr;
1908
1909 Handle exception(current, current->exception_oop());
1910 address pc = current->exception_pc();
1911
1912 // Clear out the exception oop and pc since looking up an
1913 // exception handler can cause class loading, which might throw an
1914 // exception and those fields are expected to be clear during
2146 frame caller_frame = stub_frame.sender(®_map);
2147 return caller_frame.is_deoptimized_frame();
2148 }
2149
2150 static const TypeFunc* make_register_finalizer_Type() {
2151 // create input type (domain)
2152 const Type **fields = TypeTuple::fields(1);
2153 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver
2154 // // The JavaThread* is passed to each routine as the last argument
2155 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
2156 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
2157
2158 // create result type (range)
2159 fields = TypeTuple::fields(0);
2160
2161 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2162
2163 return TypeFunc::make(domain,range);
2164 }
2165
2166 const TypeFunc *OptoRuntime::class_init_barrier_Type() {
2167 // create input type (domain)
2168 const Type** fields = TypeTuple::fields(1);
2169 fields[TypeFunc::Parms+0] = TypeKlassPtr::NOTNULL;
2170 // // The JavaThread* is passed to each routine as the last argument
2171 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
2172 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+1, fields);
2173
2174 // create result type (range)
2175 fields = TypeTuple::fields(0);
2176 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
2177 return TypeFunc::make(domain,range);
2178 }
2179
2180 #if INCLUDE_JFR
2181 static const TypeFunc* make_class_id_load_barrier_Type() {
2182 // create input type (domain)
2183 const Type **fields = TypeTuple::fields(1);
2184 fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS;
2185 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields);
2186
2187 // create result type (range)
2188 fields = TypeTuple::fields(0);
2189
2190 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields);
2191
2192 return TypeFunc::make(domain,range);
2193 }
2194 #endif // INCLUDE_JFR
2195
2196 //-----------------------------------------------------------------------------
2197 // runtime upcall support
2198 const TypeFunc *OptoRuntime::runtime_up_call_Type() {
2199 // create input type (domain)
2200 const Type **fields = TypeTuple::fields(1);
2201 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2202 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
2203
2204 // create result type (range)
2205 fields = TypeTuple::fields(0);
2206
2207 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2208
2209 return TypeFunc::make(domain,range);
2210 }
2211
2212 //-----------------------------------------------------------------------------
2213 static const TypeFunc* make_dtrace_method_entry_exit_Type() {
2214 // create input type (domain)
2215 const Type **fields = TypeTuple::fields(2);
2216 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2217 fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM; // Method*; Method we are entering
2218 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2219
2220 // create result type (range)
2221 fields = TypeTuple::fields(0);
2222
2223 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2224
2225 return TypeFunc::make(domain,range);
2226 }
2227
2228 static const TypeFunc* make_dtrace_object_alloc_Type() {
2229 // create input type (domain)
2230 const Type **fields = TypeTuple::fields(2);
2231 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2232 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object
2233
2234 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2235
2236 // create result type (range)
2237 fields = TypeTuple::fields(0);
2238
2239 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2240
2241 return TypeFunc::make(domain,range);
2242 }
2243
2244 JRT_ENTRY_NO_ASYNC_PROF(void, OptoRuntime, register_finalizer_C, OptoRuntime::register_finalizer_C(oopDesc* obj, JavaThread* current))
2245 assert(oopDesc::is_oop(obj), "must be a valid oop");
2246 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
2247 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
2248 JRT_END
2249
2250 JRT_ENTRY_NO_ASYNC_PROF(void, OptoRuntime, class_init_barrier_C, OptoRuntime::class_init_barrier_C(Klass* k, JavaThread* current))
2251 InstanceKlass* ik = InstanceKlass::cast(k);
2252 if (ik->should_be_initialized()) {
2253 ik->initialize(CHECK);
2254 } else if (UsePerfData) {
2255 _perf_OptoRuntime_class_init_barrier_redundant_count->inc();
2256 }
2257 JRT_END
2258
2259 //-----------------------------------------------------------------------------
2260
2261 NamedCounter * volatile OptoRuntime::_named_counters = nullptr;
2262
2263 //
2264 // dump the collected NamedCounters.
2265 //
2266 void OptoRuntime::print_named_counters() {
2267 int total_lock_count = 0;
2268 int eliminated_lock_count = 0;
2269
2270 NamedCounter* c = _named_counters;
2271 while (c) {
2272 if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) {
2273 int count = c->count();
2274 if (count > 0) {
2275 bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter;
2276 if (Verbose) {
2277 tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : "");
2278 }
2344 _multianewarray5_Type = multianewarray_Type(5);
2345 _multianewarrayN_Type = make_multianewarrayN_Type();
2346 _complete_monitor_enter_Type = make_complete_monitor_enter_Type();
2347 _complete_monitor_exit_Type = make_complete_monitor_exit_Type();
2348 _monitor_notify_Type = make_monitor_notify_Type();
2349 _uncommon_trap_Type = make_uncommon_trap_Type();
2350 _athrow_Type = make_athrow_Type();
2351 _rethrow_Type = make_rethrow_Type();
2352 _Math_D_D_Type = make_Math_D_D_Type();
2353 _Math_DD_D_Type = make_Math_DD_D_Type();
2354 _modf_Type = make_modf_Type();
2355 _l2f_Type = make_l2f_Type();
2356 _void_long_Type = make_void_long_Type();
2357 _void_void_Type = make_void_void_Type();
2358 _jfr_write_checkpoint_Type = make_jfr_write_checkpoint_Type();
2359 _flush_windows_Type = make_flush_windows_Type();
2360 _fast_arraycopy_Type = make_arraycopy_Type(ac_fast);
2361 _checkcast_arraycopy_Type = make_arraycopy_Type(ac_checkcast);
2362 _generic_arraycopy_Type = make_arraycopy_Type(ac_generic);
2363 _slow_arraycopy_Type = make_arraycopy_Type(ac_slow);
2364 _compile_method_Type = make_compile_method_Type();
2365 _unsafe_setmemory_Type = make_setmemory_Type();
2366 _array_fill_Type = make_array_fill_Type();
2367 _array_sort_Type = make_array_sort_Type();
2368 _array_partition_Type = make_array_partition_Type();
2369 _aescrypt_block_Type = make_aescrypt_block_Type();
2370 _cipherBlockChaining_aescrypt_Type = make_cipherBlockChaining_aescrypt_Type();
2371 _electronicCodeBook_aescrypt_Type = make_electronicCodeBook_aescrypt_Type();
2372 _counterMode_aescrypt_Type = make_counterMode_aescrypt_Type();
2373 _galoisCounterMode_aescrypt_Type = make_galoisCounterMode_aescrypt_Type();
2374 _digestBase_implCompress_with_sha3_Type = make_digestBase_implCompress_Type( /* is_sha3= */ true);
2375 _digestBase_implCompress_without_sha3_Type = make_digestBase_implCompress_Type( /* is_sha3= */ false);;
2376 _digestBase_implCompressMB_with_sha3_Type = make_digestBase_implCompressMB_Type(/* is_sha3= */ true);
2377 _digestBase_implCompressMB_without_sha3_Type = make_digestBase_implCompressMB_Type(/* is_sha3= */ false);
2378 _double_keccak_Type = make_double_keccak_Type();
2379 _multiplyToLen_Type = make_multiplyToLen_Type();
2380 _montgomeryMultiply_Type = make_montgomeryMultiply_Type();
2381 _montgomerySquare_Type = make_montgomerySquare_Type();
2382 _squareToLen_Type = make_squareToLen_Type();
2383 _mulAdd_Type = make_mulAdd_Type();
2384 _bigIntegerShift_Type = make_bigIntegerShift_Type();
2420 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
2421 trace_exception_counter++;
2422 stringStream tempst;
2423
2424 tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
2425 exception_oop->print_value_on(&tempst);
2426 tempst.print(" in ");
2427 CodeBlob* blob = CodeCache::find_blob(exception_pc);
2428 if (blob->is_nmethod()) {
2429 blob->as_nmethod()->method()->print_value_on(&tempst);
2430 } else if (blob->is_runtime_stub()) {
2431 tempst.print("<runtime-stub>");
2432 } else {
2433 tempst.print("<unknown>");
2434 }
2435 tempst.print(" at " INTPTR_FORMAT, p2i(exception_pc));
2436 tempst.print("]");
2437
2438 st->print_raw_cr(tempst.freeze());
2439 }
2440
2441 #define DO_COUNTERS2(macro2, macro1) \
2442 macro2(OptoRuntime, new_instance_C) \
2443 macro2(OptoRuntime, new_array_C) \
2444 macro2(OptoRuntime, new_array_nozero_C) \
2445 macro2(OptoRuntime, multianewarray2_C) \
2446 macro2(OptoRuntime, multianewarray3_C) \
2447 macro2(OptoRuntime, multianewarray4_C) \
2448 macro2(OptoRuntime, multianewarrayN_C) \
2449 macro2(OptoRuntime, monitor_notify_C) \
2450 macro2(OptoRuntime, monitor_notifyAll_C) \
2451 macro2(OptoRuntime, handle_exception_C_helper) \
2452 macro2(OptoRuntime, register_finalizer_C) \
2453 macro2(OptoRuntime, class_init_barrier_C) \
2454 macro1(OptoRuntime, class_init_barrier_redundant)
2455
2456 #define INIT_COUNTER_TIME_AND_CNT(sub, name) \
2457 NEWPERFTICKCOUNTERS(_perf_##sub##_##name##_timer, SUN_CI, #sub "::" #name); \
2458 NEWPERFEVENTCOUNTER(_perf_##sub##_##name##_count, SUN_CI, #sub "::" #name "_count");
2459
2460 #define INIT_COUNTER_CNT(sub, name) \
2461 NEWPERFEVENTCOUNTER(_perf_##sub##_##name##_count, SUN_CI, #sub "::" #name "_count");
2462
2463 void OptoRuntime::init_counters() {
2464 assert(CompilerConfig::is_c2_enabled(), "");
2465
2466 if (UsePerfData) {
2467 EXCEPTION_MARK;
2468
2469 DO_COUNTERS2(INIT_COUNTER_TIME_AND_CNT, INIT_COUNTER_CNT)
2470
2471 if (HAS_PENDING_EXCEPTION) {
2472 vm_exit_during_initialization("jvm_perf_init failed unexpectedly");
2473 }
2474 }
2475 }
2476 #undef INIT_COUNTER_TIME_AND_CNT
2477 #undef INIT_COUNTER_CNT
2478
2479 #define PRINT_COUNTER_TIME_AND_CNT(sub, name) { \
2480 jlong count = _perf_##sub##_##name##_count->get_value(); \
2481 if (count > 0) { \
2482 st->print_cr(" %-50s = " JLONG_FORMAT_W(6) "us (elapsed) " JLONG_FORMAT_W(6) "us (thread) (" JLONG_FORMAT_W(5) " events)", #sub "::" #name, \
2483 _perf_##sub##_##name##_timer->elapsed_counter_value_us(), \
2484 _perf_##sub##_##name##_timer->thread_counter_value_us(), \
2485 count); \
2486 }}
2487
2488 #define PRINT_COUNTER_CNT(sub, name) { \
2489 jlong count = _perf_##sub##_##name##_count->get_value(); \
2490 if (count > 0) { \
2491 st->print_cr(" %-30s = " JLONG_FORMAT_W(5) " events", #name, count); \
2492 }}
2493
2494 void OptoRuntime::print_counters_on(outputStream* st) {
2495 if (UsePerfData && ProfileRuntimeCalls && CompilerConfig::is_c2_enabled()) {
2496 DO_COUNTERS2(PRINT_COUNTER_TIME_AND_CNT, PRINT_COUNTER_CNT)
2497 } else {
2498 st->print_cr(" OptoRuntime: no info (%s is disabled)",
2499 (!CompilerConfig::is_c2_enabled() ? "C2" : (UsePerfData ? "ProfileRuntimeCalls" : "UsePerfData")));
2500 }
2501 }
2502
2503 #undef PRINT_COUNTER_TIME_AND_CNT
2504 #undef PRINT_COUNTER_CNT
2505 #undef DO_COUNTERS2
|