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/sharedRuntime.hpp"
70 #include "runtime/signature.hpp"
71 #include "runtime/stackWatermarkSet.hpp"
72 #include "runtime/synchronizer.hpp"
73 #include "runtime/threadWXSetters.inline.hpp"
74 #include "runtime/vframe.hpp"
75 #include "runtime/vframe_hp.hpp"
76 #include "runtime/vframeArray.hpp"
77 #include "utilities/copy.hpp"
78 #include "utilities/preserveException.hpp"
79
80
81 // For debugging purposes:
82 // To force FullGCALot inside a runtime function, add the following two lines
83 //
84 // Universe::release_fullgc_alot_dummy();
85 // Universe::heap()->collect();
86 //
87 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
88
89
90 #define C2_BLOB_FIELD_DEFINE(name, type) \
91 type* OptoRuntime:: BLOB_FIELD_NAME(name) = nullptr;
92 #define C2_STUB_FIELD_NAME(name) _ ## name ## _Java
93 #define C2_STUB_FIELD_DEFINE(name, f, t, r) \
94 address OptoRuntime:: C2_STUB_FIELD_NAME(name) = nullptr;
95 #define C2_JVMTI_STUB_FIELD_DEFINE(name) \
96 address OptoRuntime:: STUB_FIELD_NAME(name) = nullptr;
97 C2_STUBS_DO(C2_BLOB_FIELD_DEFINE, C2_STUB_FIELD_DEFINE, C2_JVMTI_STUB_FIELD_DEFINE)
98 #undef C2_BLOB_FIELD_DEFINE
99 #undef C2_STUB_FIELD_DEFINE
100 #undef C2_JVMTI_STUB_FIELD_DEFINE
101
102 // This should be called in an assertion at the start of OptoRuntime routines
103 // which are entered from compiled code (all of them)
104 #ifdef ASSERT
105 static bool check_compiled_frame(JavaThread* thread) {
106 assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
107 RegisterMap map(thread,
108 RegisterMap::UpdateMap::skip,
109 RegisterMap::ProcessFrames::include,
110 RegisterMap::WalkContinuation::skip);
111 frame caller = thread->last_frame().sender(&map);
112 assert(caller.is_compiled_frame(), "not being called from compiled like code");
113 return true;
114 }
115 #endif // ASSERT
116
117 /*
118 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, return_pc) \
119 var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, return_pc); \
120 if (var == nullptr) { return false; }
121 */
151 fancy_jump, \
152 pass_tls, \
153 pass_retpc); \
154 if (C2_STUB_FIELD_NAME(name) == nullptr) { return false; } \
155
156 #define C2_JVMTI_STUB_C_FUNC(name) CAST_FROM_FN_PTR(address, SharedRuntime::name)
157
158 #define GEN_C2_JVMTI_STUB(name) \
159 STUB_FIELD_NAME(name) = \
160 generate_stub(env, \
161 notify_jvmti_vthread_Type, \
162 C2_JVMTI_STUB_C_FUNC(name), \
163 C2_STUB_NAME(name), \
164 C2_STUB_ID(name), \
165 0, \
166 true, \
167 false); \
168 if (STUB_FIELD_NAME(name) == nullptr) { return false; } \
169
170 bool OptoRuntime::generate(ciEnv* env) {
171
172 C2_STUBS_DO(GEN_C2_BLOB, GEN_C2_STUB, GEN_C2_JVMTI_STUB)
173
174 return true;
175 }
176
177 #undef GEN_C2_BLOB
178
179 #undef C2_STUB_FIELD_NAME
180 #undef C2_STUB_TYPEFUNC
181 #undef C2_STUB_C_FUNC
182 #undef C2_STUB_NAME
183 #undef GEN_C2_STUB
184
185 #undef C2_JVMTI_STUB_C_FUNC
186 #undef GEN_C2_JVMTI_STUB
187 // #undef gen
188
189 const TypeFunc* OptoRuntime::_new_instance_Type = nullptr;
190 const TypeFunc* OptoRuntime::_new_array_Type = nullptr;
257 const TypeFunc* OptoRuntime::_updateBytesAdler32_Type = nullptr;
258 const TypeFunc* OptoRuntime::_osr_end_Type = nullptr;
259 const TypeFunc* OptoRuntime::_register_finalizer_Type = nullptr;
260 #if INCLUDE_JFR
261 const TypeFunc* OptoRuntime::_class_id_load_barrier_Type = nullptr;
262 #endif // INCLUDE_JFR
263 #if INCLUDE_JVMTI
264 const TypeFunc* OptoRuntime::_notify_jvmti_vthread_Type = nullptr;
265 #endif // INCLUDE_JVMTI
266 const TypeFunc* OptoRuntime::_dtrace_method_entry_exit_Type = nullptr;
267 const TypeFunc* OptoRuntime::_dtrace_object_alloc_Type = nullptr;
268
269 // Helper method to do generation of RunTimeStub's
270 address OptoRuntime::generate_stub(ciEnv* env,
271 TypeFunc_generator gen, address C_function,
272 const char *name, StubId stub_id,
273 int is_fancy_jump, bool pass_tls,
274 bool return_pc) {
275
276 // Matching the default directive, we currently have no method to match.
277 DirectiveSet* directive = DirectivesStack::getDefaultDirective(CompileBroker::compiler(CompLevel_full_optimization));
278 CompilationMemoryStatisticMark cmsm(directive);
279 ResourceMark rm;
280 Compile C(env, gen, C_function, name, stub_id, is_fancy_jump, pass_tls, return_pc, directive);
281 DirectivesStack::release(directive);
282 return C.stub_entry_point();
283 }
284
285 const char* OptoRuntime::stub_name(address entry) {
286 #ifndef PRODUCT
287 CodeBlob* cb = CodeCache::find_blob(entry);
288 RuntimeStub* rs =(RuntimeStub *)cb;
289 assert(rs != nullptr && rs->is_runtime_stub(), "not a runtime stub");
290 return rs->name();
291 #else
292 // Fast implementation for product mode (maybe it should be inlined too)
293 return "runtime stub";
294 #endif
295 }
296
297 // local methods passed as arguments to stub generator that forward
301 oopDesc* dest, jint dest_pos,
302 jint length, JavaThread* thread) {
303 SharedRuntime::slow_arraycopy_C(src, src_pos, dest, dest_pos, length, thread);
304 }
305
306 void OptoRuntime::complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current) {
307 SharedRuntime::complete_monitor_locking_C(obj, lock, current);
308 }
309
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(void, 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(void, 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(void, 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(void, 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(void, 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(void, 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(void, 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(void, 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(void, 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 static const TypeFunc* make_new_instance_Type() {
576 // create input type (domain)
577 const Type **fields = TypeTuple::fields(1);
1844 assert(reg >= 0 && reg < _last_Mach_Reg, "must be a machine register");
1845 switch (register_save_policy[reg]) {
1846 case 'C': return false; //SOC
1847 case 'E': return true ; //SOE
1848 case 'N': return false; //NS
1849 case 'A': return false; //AS
1850 }
1851 ShouldNotReachHere();
1852 return false;
1853 }
1854
1855 //-----------------------------------------------------------------------
1856 // Exceptions
1857 //
1858
1859 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg);
1860
1861 // The method is an entry that is always called by a C++ method not
1862 // directly from compiled code. Compiled code will call the C++ method following.
1863 // We can't allow async exception to be installed during exception processing.
1864 JRT_ENTRY_NO_ASYNC(address, OptoRuntime::handle_exception_C_helper(JavaThread* current, nmethod* &nm))
1865 // The frame we rethrow the exception to might not have been processed by the GC yet.
1866 // The stack watermark barrier takes care of detecting that and ensuring the frame
1867 // has updated oops.
1868 StackWatermarkSet::after_unwind(current);
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
1883 // normal bytecode execution.
1884 current->clear_exception_oop_and_pc();
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 }
2350 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
2351 trace_exception_counter++;
2352 stringStream tempst;
2353
2354 tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
2355 exception_oop->print_value_on(&tempst);
2356 tempst.print(" in ");
2357 CodeBlob* blob = CodeCache::find_blob(exception_pc);
2358 if (blob->is_nmethod()) {
2359 blob->as_nmethod()->method()->print_value_on(&tempst);
2360 } else if (blob->is_runtime_stub()) {
2361 tempst.print("<runtime-stub>");
2362 } else {
2363 tempst.print("<unknown>");
2364 }
2365 tempst.print(" at " INTPTR_FORMAT, p2i(exception_pc));
2366 tempst.print("]");
2367
2368 st->print_raw_cr(tempst.freeze());
2369 }
|
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/compilerDefinitions.inline.hpp"
36 #include "compiler/oopMap.hpp"
37 #include "gc/g1/g1HeapRegion.hpp"
38 #include "gc/shared/barrierSet.hpp"
39 #include "gc/shared/collectedHeap.hpp"
40 #include "gc/shared/gcLocker.hpp"
41 #include "interpreter/bytecode.hpp"
42 #include "interpreter/interpreter.hpp"
43 #include "interpreter/linkResolver.hpp"
44 #include "logging/log.hpp"
45 #include "logging/logStream.hpp"
46 #include "memory/oopFactory.hpp"
47 #include "memory/resourceArea.hpp"
48 #include "oops/klass.inline.hpp"
49 #include "oops/objArrayKlass.hpp"
50 #include "oops/oop.inline.hpp"
51 #include "oops/typeArrayOop.inline.hpp"
52 #include "opto/ad.hpp"
53 #include "opto/addnode.hpp"
54 #include "opto/callnode.hpp"
55 #include "opto/cfgnode.hpp"
56 #include "opto/graphKit.hpp"
57 #include "opto/machnode.hpp"
58 #include "opto/matcher.hpp"
59 #include "opto/memnode.hpp"
60 #include "opto/mulnode.hpp"
61 #include "opto/output.hpp"
62 #include "opto/runtime.hpp"
63 #include "opto/subnode.hpp"
64 #include "prims/jvmtiExport.hpp"
65 #include "runtime/atomicAccess.hpp"
66 #include "runtime/frame.inline.hpp"
67 #include "runtime/handles.inline.hpp"
68 #include "runtime/interfaceSupport.inline.hpp"
69 #include "runtime/java.hpp"
70 #include "runtime/javaCalls.hpp"
71 #include "runtime/perfData.inline.hpp"
72 #include "runtime/sharedRuntime.hpp"
73 #include "runtime/signature.hpp"
74 #include "runtime/stackWatermarkSet.hpp"
75 #include "runtime/synchronizer.hpp"
76 #include "runtime/threadWXSetters.inline.hpp"
77 #include "runtime/vframe.hpp"
78 #include "runtime/vframe_hp.hpp"
79 #include "runtime/vframeArray.hpp"
80 #include "services/management.hpp"
81 #include "utilities/copy.hpp"
82 #include "utilities/preserveException.hpp"
83
84
85 // For debugging purposes:
86 // To force FullGCALot inside a runtime function, add the following two lines
87 //
88 // Universe::release_fullgc_alot_dummy();
89 // Universe::heap()->collect();
90 //
91 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
92
93
94 #define C2_BLOB_FIELD_DEFINE(name, type) \
95 type* OptoRuntime:: BLOB_FIELD_NAME(name) = nullptr;
96 #define C2_STUB_FIELD_NAME(name) _ ## name ## _Java
97 #define C2_STUB_FIELD_DEFINE(name, f, t, r) \
98 address OptoRuntime:: C2_STUB_FIELD_NAME(name) = nullptr;
99 #define C2_JVMTI_STUB_FIELD_DEFINE(name) \
100 address OptoRuntime:: STUB_FIELD_NAME(name) = nullptr;
101 C2_STUBS_DO(C2_BLOB_FIELD_DEFINE, C2_STUB_FIELD_DEFINE, C2_JVMTI_STUB_FIELD_DEFINE)
102 #undef C2_BLOB_FIELD_DEFINE
103 #undef C2_STUB_FIELD_DEFINE
104 #undef C2_JVMTI_STUB_FIELD_DEFINE
105
106 address OptoRuntime::_vtable_must_compile_Java = nullptr;
107
108 PerfCounter* _perf_OptoRuntime_class_init_barrier_redundant_count = nullptr;
109
110 // This should be called in an assertion at the start of OptoRuntime routines
111 // which are entered from compiled code (all of them)
112 #ifdef ASSERT
113 static bool check_compiled_frame(JavaThread* thread) {
114 assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
115 RegisterMap map(thread,
116 RegisterMap::UpdateMap::skip,
117 RegisterMap::ProcessFrames::include,
118 RegisterMap::WalkContinuation::skip);
119 frame caller = thread->last_frame().sender(&map);
120 assert(caller.is_compiled_frame(), "not being called from compiled like code");
121 return true;
122 }
123 #endif // ASSERT
124
125 /*
126 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, return_pc) \
127 var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, return_pc); \
128 if (var == nullptr) { return false; }
129 */
159 fancy_jump, \
160 pass_tls, \
161 pass_retpc); \
162 if (C2_STUB_FIELD_NAME(name) == nullptr) { return false; } \
163
164 #define C2_JVMTI_STUB_C_FUNC(name) CAST_FROM_FN_PTR(address, SharedRuntime::name)
165
166 #define GEN_C2_JVMTI_STUB(name) \
167 STUB_FIELD_NAME(name) = \
168 generate_stub(env, \
169 notify_jvmti_vthread_Type, \
170 C2_JVMTI_STUB_C_FUNC(name), \
171 C2_STUB_NAME(name), \
172 C2_STUB_ID(name), \
173 0, \
174 true, \
175 false); \
176 if (STUB_FIELD_NAME(name) == nullptr) { return false; } \
177
178 bool OptoRuntime::generate(ciEnv* env) {
179 init_counters();
180
181 C2_STUBS_DO(GEN_C2_BLOB, GEN_C2_STUB, GEN_C2_JVMTI_STUB)
182
183 return true;
184 }
185
186 #undef GEN_C2_BLOB
187
188 #undef C2_STUB_FIELD_NAME
189 #undef C2_STUB_TYPEFUNC
190 #undef C2_STUB_C_FUNC
191 #undef C2_STUB_NAME
192 #undef GEN_C2_STUB
193
194 #undef C2_JVMTI_STUB_C_FUNC
195 #undef GEN_C2_JVMTI_STUB
196 // #undef gen
197
198 const TypeFunc* OptoRuntime::_new_instance_Type = nullptr;
199 const TypeFunc* OptoRuntime::_new_array_Type = nullptr;
266 const TypeFunc* OptoRuntime::_updateBytesAdler32_Type = nullptr;
267 const TypeFunc* OptoRuntime::_osr_end_Type = nullptr;
268 const TypeFunc* OptoRuntime::_register_finalizer_Type = nullptr;
269 #if INCLUDE_JFR
270 const TypeFunc* OptoRuntime::_class_id_load_barrier_Type = nullptr;
271 #endif // INCLUDE_JFR
272 #if INCLUDE_JVMTI
273 const TypeFunc* OptoRuntime::_notify_jvmti_vthread_Type = nullptr;
274 #endif // INCLUDE_JVMTI
275 const TypeFunc* OptoRuntime::_dtrace_method_entry_exit_Type = nullptr;
276 const TypeFunc* OptoRuntime::_dtrace_object_alloc_Type = nullptr;
277
278 // Helper method to do generation of RunTimeStub's
279 address OptoRuntime::generate_stub(ciEnv* env,
280 TypeFunc_generator gen, address C_function,
281 const char *name, StubId stub_id,
282 int is_fancy_jump, bool pass_tls,
283 bool return_pc) {
284
285 // Matching the default directive, we currently have no method to match.
286 DirectiveSet* directive = DirectivesStack::getDefaultDirective(CompilerThread::current()->compiler());
287 CompilationMemoryStatisticMark cmsm(directive);
288 ResourceMark rm;
289 Compile C(env, gen, C_function, name, stub_id, is_fancy_jump, pass_tls, return_pc, directive);
290 DirectivesStack::release(directive);
291 return C.stub_entry_point();
292 }
293
294 const char* OptoRuntime::stub_name(address entry) {
295 #ifndef PRODUCT
296 CodeBlob* cb = CodeCache::find_blob(entry);
297 RuntimeStub* rs =(RuntimeStub *)cb;
298 assert(rs != nullptr && rs->is_runtime_stub(), "not a runtime stub");
299 return rs->name();
300 #else
301 // Fast implementation for product mode (maybe it should be inlined too)
302 return "runtime stub";
303 #endif
304 }
305
306 // local methods passed as arguments to stub generator that forward
310 oopDesc* dest, jint dest_pos,
311 jint length, JavaThread* thread) {
312 SharedRuntime::slow_arraycopy_C(src, src_pos, dest, dest_pos, length, thread);
313 }
314
315 void OptoRuntime::complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current) {
316 SharedRuntime::complete_monitor_locking_C(obj, lock, current);
317 }
318
319
320 //=============================================================================
321 // Opto compiler runtime routines
322 //=============================================================================
323
324
325 //=============================allocation======================================
326 // We failed the fast-path allocation. Now we need to do a scavenge or GC
327 // and try allocation again.
328
329 // object allocation
330 JRT_BLOCK_ENTRY_PROF(void, OptoRuntime, new_instance_C, OptoRuntime::new_instance_C(Klass* klass, JavaThread* current))
331 JRT_BLOCK;
332 #ifndef PRODUCT
333 SharedRuntime::_new_instance_ctr++; // new instance requires GC
334 #endif
335 assert(check_compiled_frame(current), "incorrect caller");
336
337 // These checks are cheap to make and support reflective allocation.
338 int lh = klass->layout_helper();
339 if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
340 Handle holder(current, klass->klass_holder()); // keep the klass alive
341 klass->check_valid_for_instantiation(false, THREAD);
342 if (!HAS_PENDING_EXCEPTION) {
343 InstanceKlass::cast(klass)->initialize(THREAD);
344 }
345 }
346
347 if (!HAS_PENDING_EXCEPTION) {
348 // Scavenge and allocate an instance.
349 Handle holder(current, klass->klass_holder()); // keep the klass alive
350 oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
351 current->set_vm_result_oop(result);
352
353 // Pass oops back through thread local storage. Our apparent type to Java
354 // is that we return an oop, but we can block on exit from this routine and
355 // a GC can trash the oop in C's return register. The generated stub will
356 // fetch the oop from TLS after any possible GC.
357 }
358
359 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
360 JRT_BLOCK_END;
361
362 // inform GC that we won't do card marks for initializing writes.
363 SharedRuntime::on_slowpath_allocation_exit(current);
364 JRT_END
365
366
367 // array allocation
368 JRT_BLOCK_ENTRY_PROF(void, OptoRuntime, new_array_C, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread* current))
369 JRT_BLOCK;
370 #ifndef PRODUCT
371 SharedRuntime::_new_array_ctr++; // new array requires GC
372 #endif
373 assert(check_compiled_frame(current), "incorrect caller");
374
375 // Scavenge and allocate an instance.
376 oop result;
377
378 if (array_type->is_typeArray_klass()) {
379 // The oopFactory likes to work with the element type.
380 // (We could bypass the oopFactory, since it doesn't add much value.)
381 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
382 result = oopFactory::new_typeArray(elem_type, len, THREAD);
383 } else {
384 // Although the oopFactory likes to work with the elem_type,
385 // the compiler prefers the array_type, since it must already have
386 // that latter value in hand for the fast path.
387 Handle holder(current, array_type->klass_holder()); // keep the array klass alive
388 Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass();
389 result = oopFactory::new_objArray(elem_type, len, THREAD);
390 }
391
392 // Pass oops back through thread local storage. Our apparent type to Java
393 // is that we return an oop, but we can block on exit from this routine and
394 // a GC can trash the oop in C's return register. The generated stub will
395 // fetch the oop from TLS after any possible GC.
396 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
397 current->set_vm_result_oop(result);
398 JRT_BLOCK_END;
399
400 // inform GC that we won't do card marks for initializing writes.
401 SharedRuntime::on_slowpath_allocation_exit(current);
402 JRT_END
403
404 // array allocation without zeroing
405 JRT_BLOCK_ENTRY_PROF(void, OptoRuntime, new_array_nozero_C, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread* current))
406 JRT_BLOCK;
407 #ifndef PRODUCT
408 SharedRuntime::_new_array_ctr++; // new array requires GC
409 #endif
410 assert(check_compiled_frame(current), "incorrect caller");
411
412 // Scavenge and allocate an instance.
413 oop result;
414
415 assert(array_type->is_typeArray_klass(), "should be called only for type array");
416 // The oopFactory likes to work with the element type.
417 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
418 result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD);
419
420 // Pass oops back through thread local storage. Our apparent type to Java
421 // is that we return an oop, but we can block on exit from this routine and
422 // a GC can trash the oop in C's return register. The generated stub will
423 // fetch the oop from TLS after any possible GC.
424 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
425 current->set_vm_result_oop(result);
437 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
438 size_t hs_bytes = arrayOopDesc::base_offset_in_bytes(elem_type);
439 assert(is_aligned(hs_bytes, BytesPerInt), "must be 4 byte aligned");
440 HeapWord* obj = cast_from_oop<HeapWord*>(result);
441 if (!is_aligned(hs_bytes, BytesPerLong)) {
442 *reinterpret_cast<jint*>(reinterpret_cast<char*>(obj) + hs_bytes) = 0;
443 hs_bytes += BytesPerInt;
444 }
445
446 // Optimized zeroing.
447 assert(is_aligned(hs_bytes, BytesPerLong), "must be 8-byte aligned");
448 const size_t aligned_hs = hs_bytes / BytesPerLong;
449 Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs);
450 }
451
452 JRT_END
453
454 // Note: multianewarray for one dimension is handled inline by GraphKit::new_array.
455
456 // multianewarray for 2 dimensions
457 JRT_ENTRY_PROF(void, OptoRuntime, multianewarray2_C, OptoRuntime::multianewarray2_C(Klass* elem_type, int len1, int len2, JavaThread* current))
458 #ifndef PRODUCT
459 SharedRuntime::_multi2_ctr++; // multianewarray for 1 dimension
460 #endif
461 assert(check_compiled_frame(current), "incorrect caller");
462 assert(elem_type->is_klass(), "not a class");
463 jint dims[2];
464 dims[0] = len1;
465 dims[1] = len2;
466 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
467 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD);
468 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
469 current->set_vm_result_oop(obj);
470 JRT_END
471
472 // multianewarray for 3 dimensions
473 JRT_ENTRY_PROF(void, OptoRuntime, multianewarray3_C, OptoRuntime::multianewarray3_C(Klass* elem_type, int len1, int len2, int len3, JavaThread* current))
474 #ifndef PRODUCT
475 SharedRuntime::_multi3_ctr++; // multianewarray for 1 dimension
476 #endif
477 assert(check_compiled_frame(current), "incorrect caller");
478 assert(elem_type->is_klass(), "not a class");
479 jint dims[3];
480 dims[0] = len1;
481 dims[1] = len2;
482 dims[2] = len3;
483 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
484 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD);
485 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
486 current->set_vm_result_oop(obj);
487 JRT_END
488
489 // multianewarray for 4 dimensions
490 JRT_ENTRY_PROF(void, OptoRuntime, multianewarray4_C, OptoRuntime::multianewarray4_C(Klass* elem_type, int len1, int len2, int len3, int len4, JavaThread* current))
491 #ifndef PRODUCT
492 SharedRuntime::_multi4_ctr++; // multianewarray for 1 dimension
493 #endif
494 assert(check_compiled_frame(current), "incorrect caller");
495 assert(elem_type->is_klass(), "not a class");
496 jint dims[4];
497 dims[0] = len1;
498 dims[1] = len2;
499 dims[2] = len3;
500 dims[3] = len4;
501 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
502 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD);
503 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
504 current->set_vm_result_oop(obj);
505 JRT_END
506
507 // multianewarray for 5 dimensions
508 JRT_ENTRY(void, OptoRuntime::multianewarray5_C(Klass* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread* current))
509 #ifndef PRODUCT
510 SharedRuntime::_multi5_ctr++; // multianewarray for 1 dimension
511 #endif
512 assert(check_compiled_frame(current), "incorrect caller");
513 assert(elem_type->is_klass(), "not a class");
514 jint dims[5];
515 dims[0] = len1;
516 dims[1] = len2;
517 dims[2] = len3;
518 dims[3] = len4;
519 dims[4] = len5;
520 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
521 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD);
522 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
523 current->set_vm_result_oop(obj);
524 JRT_END
525
526 JRT_ENTRY_PROF(void, OptoRuntime, multianewarrayN_C, OptoRuntime::multianewarrayN_C(Klass* elem_type, arrayOopDesc* dims, JavaThread* current))
527 assert(check_compiled_frame(current), "incorrect caller");
528 assert(elem_type->is_klass(), "not a class");
529 assert(oop(dims)->is_typeArray(), "not an array");
530
531 ResourceMark rm;
532 jint len = dims->length();
533 assert(len > 0, "Dimensions array should contain data");
534 jint *c_dims = NEW_RESOURCE_ARRAY(jint, len);
535 ArrayAccess<>::arraycopy_to_native<>(dims, typeArrayOopDesc::element_offset<jint>(0),
536 c_dims, len);
537
538 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
539 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(len, c_dims, THREAD);
540 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
541 current->set_vm_result_oop(obj);
542 JRT_END
543
544 JRT_BLOCK_ENTRY_PROF(void, OptoRuntime, monitor_notify_C, OptoRuntime::monitor_notify_C(oopDesc* obj, JavaThread* current))
545
546 // Very few notify/notifyAll operations find any threads on the waitset, so
547 // the dominant fast-path is to simply return.
548 // Relatedly, it's critical that notify/notifyAll be fast in order to
549 // reduce lock hold times.
550 if (!SafepointSynchronize::is_synchronizing()) {
551 if (ObjectSynchronizer::quick_notify(obj, current, false)) {
552 return;
553 }
554 }
555
556 // This is the case the fast-path above isn't provisioned to handle.
557 // The fast-path is designed to handle frequently arising cases in an efficient manner.
558 // (The fast-path is just a degenerate variant of the slow-path).
559 // Perform the dreaded state transition and pass control into the slow-path.
560 JRT_BLOCK;
561 Handle h_obj(current, obj);
562 ObjectSynchronizer::notify(h_obj, CHECK);
563 JRT_BLOCK_END;
564 JRT_END
565
566 JRT_BLOCK_ENTRY_PROF(void, OptoRuntime, monitor_notifyAll_C, OptoRuntime::monitor_notifyAll_C(oopDesc* obj, JavaThread* current))
567
568 if (!SafepointSynchronize::is_synchronizing() ) {
569 if (ObjectSynchronizer::quick_notify(obj, current, true)) {
570 return;
571 }
572 }
573
574 // This is the case the fast-path above isn't provisioned to handle.
575 // The fast-path is designed to handle frequently arising cases in an efficient manner.
576 // (The fast-path is just a degenerate variant of the slow-path).
577 // Perform the dreaded state transition and pass control into the slow-path.
578 JRT_BLOCK;
579 Handle h_obj(current, obj);
580 ObjectSynchronizer::notifyall(h_obj, CHECK);
581 JRT_BLOCK_END;
582 JRT_END
583
584 static const TypeFunc* make_new_instance_Type() {
585 // create input type (domain)
586 const Type **fields = TypeTuple::fields(1);
1853 assert(reg >= 0 && reg < _last_Mach_Reg, "must be a machine register");
1854 switch (register_save_policy[reg]) {
1855 case 'C': return false; //SOC
1856 case 'E': return true ; //SOE
1857 case 'N': return false; //NS
1858 case 'A': return false; //AS
1859 }
1860 ShouldNotReachHere();
1861 return false;
1862 }
1863
1864 //-----------------------------------------------------------------------
1865 // Exceptions
1866 //
1867
1868 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg);
1869
1870 // The method is an entry that is always called by a C++ method not
1871 // directly from compiled code. Compiled code will call the C++ method following.
1872 // We can't allow async exception to be installed during exception processing.
1873 JRT_ENTRY_NO_ASYNC_PROF(address, OptoRuntime, handle_exception_C_helper, OptoRuntime::handle_exception_C_helper(JavaThread* current, nmethod* &nm))
1874 // The frame we rethrow the exception to might not have been processed by the GC yet.
1875 // The stack watermark barrier takes care of detecting that and ensuring the frame
1876 // has updated oops.
1877 StackWatermarkSet::after_unwind(current);
1878
1879 // Do not confuse exception_oop with pending_exception. The exception_oop
1880 // is only used to pass arguments into the method. Not for general
1881 // exception handling. DO NOT CHANGE IT to use pending_exception, since
1882 // the runtime stubs checks this on exit.
1883 assert(current->exception_oop() != nullptr, "exception oop is found");
1884 address handler_address = nullptr;
1885
1886 Handle exception(current, current->exception_oop());
1887 address pc = current->exception_pc();
1888
1889 // Clear out the exception oop and pc since looking up an
1890 // exception handler can cause class loading, which might throw an
1891 // exception and those fields are expected to be clear during
1892 // normal bytecode execution.
1893 current->clear_exception_oop_and_pc();
2123 frame caller_frame = stub_frame.sender(®_map);
2124 return caller_frame.is_deoptimized_frame();
2125 }
2126
2127 static const TypeFunc* make_register_finalizer_Type() {
2128 // create input type (domain)
2129 const Type **fields = TypeTuple::fields(1);
2130 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver
2131 // // The JavaThread* is passed to each routine as the last argument
2132 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
2133 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
2134
2135 // create result type (range)
2136 fields = TypeTuple::fields(0);
2137
2138 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2139
2140 return TypeFunc::make(domain,range);
2141 }
2142
2143 const TypeFunc *OptoRuntime::class_init_barrier_Type() {
2144 // create input type (domain)
2145 const Type** fields = TypeTuple::fields(1);
2146 fields[TypeFunc::Parms+0] = TypeKlassPtr::NOTNULL;
2147 // // The JavaThread* is passed to each routine as the last argument
2148 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
2149 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+1, fields);
2150
2151 // create result type (range)
2152 fields = TypeTuple::fields(0);
2153 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
2154 return TypeFunc::make(domain,range);
2155 }
2156
2157 #if INCLUDE_JFR
2158 static const TypeFunc* make_class_id_load_barrier_Type() {
2159 // create input type (domain)
2160 const Type **fields = TypeTuple::fields(1);
2161 fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS;
2162 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields);
2163
2164 // create result type (range)
2165 fields = TypeTuple::fields(0);
2166
2167 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields);
2168
2169 return TypeFunc::make(domain,range);
2170 }
2171 #endif // INCLUDE_JFR
2172
2173 //-----------------------------------------------------------------------------
2174 // runtime upcall support
2175 const TypeFunc *OptoRuntime::runtime_up_call_Type() {
2176 // create input type (domain)
2177 const Type **fields = TypeTuple::fields(1);
2178 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2179 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
2180
2181 // create result type (range)
2182 fields = TypeTuple::fields(0);
2183
2184 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2185
2186 return TypeFunc::make(domain,range);
2187 }
2188
2189 //-----------------------------------------------------------------------------
2190 static const TypeFunc* make_dtrace_method_entry_exit_Type() {
2191 // create input type (domain)
2192 const Type **fields = TypeTuple::fields(2);
2193 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2194 fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM; // Method*; Method we are entering
2195 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2196
2197 // create result type (range)
2198 fields = TypeTuple::fields(0);
2199
2200 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2201
2202 return TypeFunc::make(domain,range);
2203 }
2204
2205 static const TypeFunc* make_dtrace_object_alloc_Type() {
2206 // create input type (domain)
2207 const Type **fields = TypeTuple::fields(2);
2208 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
2209 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object
2210
2211 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
2212
2213 // create result type (range)
2214 fields = TypeTuple::fields(0);
2215
2216 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
2217
2218 return TypeFunc::make(domain,range);
2219 }
2220
2221 JRT_ENTRY_NO_ASYNC_PROF(void, OptoRuntime, register_finalizer_C, OptoRuntime::register_finalizer_C(oopDesc* obj, JavaThread* current))
2222 assert(oopDesc::is_oop(obj), "must be a valid oop");
2223 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
2224 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
2225 JRT_END
2226
2227 JRT_ENTRY_NO_ASYNC_PROF(void, OptoRuntime, class_init_barrier_C, OptoRuntime::class_init_barrier_C(Klass* k, JavaThread* current))
2228 InstanceKlass* ik = InstanceKlass::cast(k);
2229 if (ik->should_be_initialized()) {
2230 ik->initialize(CHECK);
2231 } else if (UsePerfData) {
2232 _perf_OptoRuntime_class_init_barrier_redundant_count->inc();
2233 }
2234 JRT_END
2235
2236 //-----------------------------------------------------------------------------
2237
2238 NamedCounter * volatile OptoRuntime::_named_counters = nullptr;
2239
2240 //
2241 // dump the collected NamedCounters.
2242 //
2243 void OptoRuntime::print_named_counters() {
2244 int total_lock_count = 0;
2245 int eliminated_lock_count = 0;
2246
2247 NamedCounter* c = _named_counters;
2248 while (c) {
2249 if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) {
2250 int count = c->count();
2251 if (count > 0) {
2252 bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter;
2253 if (Verbose) {
2254 tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : "");
2255 }
2398 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
2399 trace_exception_counter++;
2400 stringStream tempst;
2401
2402 tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
2403 exception_oop->print_value_on(&tempst);
2404 tempst.print(" in ");
2405 CodeBlob* blob = CodeCache::find_blob(exception_pc);
2406 if (blob->is_nmethod()) {
2407 blob->as_nmethod()->method()->print_value_on(&tempst);
2408 } else if (blob->is_runtime_stub()) {
2409 tempst.print("<runtime-stub>");
2410 } else {
2411 tempst.print("<unknown>");
2412 }
2413 tempst.print(" at " INTPTR_FORMAT, p2i(exception_pc));
2414 tempst.print("]");
2415
2416 st->print_raw_cr(tempst.freeze());
2417 }
2418
2419 #define DO_COUNTERS2(macro2, macro1) \
2420 macro2(OptoRuntime, new_instance_C) \
2421 macro2(OptoRuntime, new_array_C) \
2422 macro2(OptoRuntime, new_array_nozero_C) \
2423 macro2(OptoRuntime, multianewarray2_C) \
2424 macro2(OptoRuntime, multianewarray3_C) \
2425 macro2(OptoRuntime, multianewarray4_C) \
2426 macro2(OptoRuntime, multianewarrayN_C) \
2427 macro2(OptoRuntime, monitor_notify_C) \
2428 macro2(OptoRuntime, monitor_notifyAll_C) \
2429 macro2(OptoRuntime, handle_exception_C_helper) \
2430 macro2(OptoRuntime, register_finalizer_C) \
2431 macro2(OptoRuntime, class_init_barrier_C) \
2432 macro1(OptoRuntime, class_init_barrier_redundant)
2433
2434 #define INIT_COUNTER_TIME_AND_CNT(sub, name) \
2435 NEWPERFTICKCOUNTERS(_perf_##sub##_##name##_timer, SUN_CI, #sub "::" #name); \
2436 NEWPERFEVENTCOUNTER(_perf_##sub##_##name##_count, SUN_CI, #sub "::" #name "_count");
2437
2438 #define INIT_COUNTER_CNT(sub, name) \
2439 NEWPERFEVENTCOUNTER(_perf_##sub##_##name##_count, SUN_CI, #sub "::" #name "_count");
2440
2441 void OptoRuntime::init_counters() {
2442 assert(CompilerConfig::is_c2_enabled(), "");
2443
2444 if (UsePerfData) {
2445 EXCEPTION_MARK;
2446
2447 DO_COUNTERS2(INIT_COUNTER_TIME_AND_CNT, INIT_COUNTER_CNT)
2448
2449 if (HAS_PENDING_EXCEPTION) {
2450 vm_exit_during_initialization("jvm_perf_init failed unexpectedly");
2451 }
2452 }
2453 }
2454 #undef INIT_COUNTER_TIME_AND_CNT
2455 #undef INIT_COUNTER_CNT
2456
2457 #define PRINT_COUNTER_TIME_AND_CNT(sub, name) { \
2458 jlong count = _perf_##sub##_##name##_count->get_value(); \
2459 if (count > 0) { \
2460 st->print_cr(" %-50s = " JLONG_FORMAT_W(6) "us (elapsed) " JLONG_FORMAT_W(6) "us (thread) (" JLONG_FORMAT_W(5) " events)", #sub "::" #name, \
2461 _perf_##sub##_##name##_timer->elapsed_counter_value_us(), \
2462 _perf_##sub##_##name##_timer->thread_counter_value_us(), \
2463 count); \
2464 }}
2465
2466 #define PRINT_COUNTER_CNT(sub, name) { \
2467 jlong count = _perf_##sub##_##name##_count->get_value(); \
2468 if (count > 0) { \
2469 st->print_cr(" %-30s = " JLONG_FORMAT_W(5) " events", #name, count); \
2470 }}
2471
2472 void OptoRuntime::print_counters_on(outputStream* st) {
2473 if (UsePerfData && ProfileRuntimeCalls && CompilerConfig::is_c2_enabled()) {
2474 DO_COUNTERS2(PRINT_COUNTER_TIME_AND_CNT, PRINT_COUNTER_CNT)
2475 } else {
2476 st->print_cr(" OptoRuntime: no info (%s is disabled)",
2477 (!CompilerConfig::is_c2_enabled() ? "C2" : (UsePerfData ? "ProfileRuntimeCalls" : "UsePerfData")));
2478 }
2479 }
2480
2481 #undef PRINT_COUNTER_TIME_AND_CNT
2482 #undef PRINT_COUNTER_CNT
2483 #undef DO_COUNTERS2
|