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 "precompiled.hpp"
26 #include "classfile/vmClasses.hpp"
27 #include "classfile/vmSymbols.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/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/objArrayKlass.hpp"
48 #include "oops/klass.inline.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/atomic.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/threadCritical.hpp"
74 #include "runtime/threadWXSetters.inline.hpp"
75 #include "runtime/vframe.hpp"
76 #include "runtime/vframeArray.hpp"
77 #include "runtime/vframe_hp.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 #define C2_JVMTI_STUB_FIELD_DEFINE(name) \
97 address OptoRuntime:: STUB_FIELD_NAME(name) = nullptr;
98 C2_STUBS_DO(C2_BLOB_FIELD_DEFINE, C2_STUB_FIELD_DEFINE, C2_JVMTI_STUB_FIELD_DEFINE)
99 #undef C2_BLOB_FIELD_DEFINE
100 #undef C2_STUB_FIELD_DEFINE
101 #undef C2_JVMTI_STUB_FIELD_DEFINE
102
103 #define C2_BLOB_NAME_DEFINE(name, type) "C2 Runtime " # name "_blob",
104 #define C2_STUB_NAME_DEFINE(name, f, t, r) "C2 Runtime " # name,
105 #define C2_JVMTI_STUB_NAME_DEFINE(name) "C2 Runtime " # name,
106 const char* OptoRuntime::_stub_names[] = {
107 C2_STUBS_DO(C2_BLOB_NAME_DEFINE, C2_STUB_NAME_DEFINE, C2_JVMTI_STUB_NAME_DEFINE)
108 };
109 #undef C2_BLOB_NAME_DEFINE
110 #undef C2_STUB_NAME_DEFINE
111 #undef C2_JVMTI_STUB_NAME_DEFINE
112
113 // This should be called in an assertion at the start of OptoRuntime routines
114 // which are entered from compiled code (all of them)
115 #ifdef ASSERT
116 static bool check_compiled_frame(JavaThread* thread) {
117 assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
118 RegisterMap map(thread,
119 RegisterMap::UpdateMap::skip,
120 RegisterMap::ProcessFrames::include,
121 RegisterMap::WalkContinuation::skip);
122 frame caller = thread->last_frame().sender(&map);
123 assert(caller.is_compiled_frame(), "not being called from compiled like code");
124 return true;
125 }
126 #endif // ASSERT
127
128 /*
129 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, return_pc) \
130 var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, return_pc); \
131 if (var == nullptr) { return false; }
132 */
157 C2_STUB_NAME(name), \
158 fancy_jump, \
159 pass_tls, \
160 pass_retpc); \
161 if (C2_STUB_FIELD_NAME(name) == nullptr) { return false; } \
162
163 #define C2_JVMTI_STUB_C_FUNC(name) CAST_FROM_FN_PTR(address, SharedRuntime::name)
164
165 #define GEN_C2_JVMTI_STUB(name) \
166 STUB_FIELD_NAME(name) = \
167 generate_stub(env, \
168 notify_jvmti_vthread_Type, \
169 C2_JVMTI_STUB_C_FUNC(name), \
170 C2_STUB_NAME(name), \
171 0, \
172 true, \
173 false); \
174 if (STUB_FIELD_NAME(name) == nullptr) { return false; } \
175
176 bool OptoRuntime::generate(ciEnv* env) {
177
178 C2_STUBS_DO(GEN_C2_BLOB, GEN_C2_STUB, GEN_C2_JVMTI_STUB)
179
180 return true;
181 }
182
183 #undef GEN_C2_BLOB
184
185 #undef C2_STUB_FIELD_NAME
186 #undef C2_STUB_TYPEFUNC
187 #undef C2_STUB_C_FUNC
188 #undef C2_STUB_NAME
189 #undef GEN_C2_STUB
190
191 #undef C2_JVMTI_STUB_C_FUNC
192 #undef GEN_C2_JVMTI_STUB
193 // #undef gen
194
195
196 // Helper method to do generation of RunTimeStub's
197 address OptoRuntime::generate_stub(ciEnv* env,
198 TypeFunc_generator gen, address C_function,
199 const char *name, int is_fancy_jump,
200 bool pass_tls,
201 bool return_pc) {
202
203 // Matching the default directive, we currently have no method to match.
204 DirectiveSet* directive = DirectivesStack::getDefaultDirective(CompileBroker::compiler(CompLevel_full_optimization));
205 ResourceMark rm;
206 Compile C(env, gen, C_function, name, is_fancy_jump, pass_tls, return_pc, directive);
207 DirectivesStack::release(directive);
208 return C.stub_entry_point();
209 }
210
211 const char* OptoRuntime::stub_name(address entry) {
212 #ifndef PRODUCT
213 CodeBlob* cb = CodeCache::find_blob(entry);
214 RuntimeStub* rs =(RuntimeStub *)cb;
215 assert(rs != nullptr && rs->is_runtime_stub(), "not a runtime stub");
216 return rs->name();
217 #else
218 // Fast implementation for product mode (maybe it should be inlined too)
219 return "runtime stub";
220 #endif
221 }
222
223 // local methods passed as arguments to stub generator that forward
224 // control to corresponding JRT methods of SharedRuntime
227 oopDesc* dest, jint dest_pos,
228 jint length, JavaThread* thread) {
229 SharedRuntime::slow_arraycopy_C(src, src_pos, dest, dest_pos, length, thread);
230 }
231
232 void OptoRuntime::complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current) {
233 SharedRuntime::complete_monitor_locking_C(obj, lock, current);
234 }
235
236
237 //=============================================================================
238 // Opto compiler runtime routines
239 //=============================================================================
240
241
242 //=============================allocation======================================
243 // We failed the fast-path allocation. Now we need to do a scavenge or GC
244 // and try allocation again.
245
246 // object allocation
247 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, JavaThread* current))
248 JRT_BLOCK;
249 #ifndef PRODUCT
250 SharedRuntime::_new_instance_ctr++; // new instance requires GC
251 #endif
252 assert(check_compiled_frame(current), "incorrect caller");
253
254 // These checks are cheap to make and support reflective allocation.
255 int lh = klass->layout_helper();
256 if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
257 Handle holder(current, klass->klass_holder()); // keep the klass alive
258 klass->check_valid_for_instantiation(false, THREAD);
259 if (!HAS_PENDING_EXCEPTION) {
260 InstanceKlass::cast(klass)->initialize(THREAD);
261 }
262 }
263
264 if (!HAS_PENDING_EXCEPTION) {
265 // Scavenge and allocate an instance.
266 Handle holder(current, klass->klass_holder()); // keep the klass alive
267 oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
268 current->set_vm_result(result);
269
270 // Pass oops back through thread local storage. Our apparent type to Java
271 // is that we return an oop, but we can block on exit from this routine and
272 // a GC can trash the oop in C's return register. The generated stub will
273 // fetch the oop from TLS after any possible GC.
274 }
275
276 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
277 JRT_BLOCK_END;
278
279 // inform GC that we won't do card marks for initializing writes.
280 SharedRuntime::on_slowpath_allocation_exit(current);
281 JRT_END
282
283
284 // array allocation
285 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread* current))
286 JRT_BLOCK;
287 #ifndef PRODUCT
288 SharedRuntime::_new_array_ctr++; // new array requires GC
289 #endif
290 assert(check_compiled_frame(current), "incorrect caller");
291
292 // Scavenge and allocate an instance.
293 oop result;
294
295 if (array_type->is_typeArray_klass()) {
296 // The oopFactory likes to work with the element type.
297 // (We could bypass the oopFactory, since it doesn't add much value.)
298 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
299 result = oopFactory::new_typeArray(elem_type, len, THREAD);
300 } else {
301 // Although the oopFactory likes to work with the elem_type,
302 // the compiler prefers the array_type, since it must already have
303 // that latter value in hand for the fast path.
304 Handle holder(current, array_type->klass_holder()); // keep the array klass alive
305 Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass();
306 result = oopFactory::new_objArray(elem_type, len, THREAD);
307 }
308
309 // Pass oops back through thread local storage. Our apparent type to Java
310 // is that we return an oop, but we can block on exit from this routine and
311 // a GC can trash the oop in C's return register. The generated stub will
312 // fetch the oop from TLS after any possible GC.
313 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
314 current->set_vm_result(result);
315 JRT_BLOCK_END;
316
317 // inform GC that we won't do card marks for initializing writes.
318 SharedRuntime::on_slowpath_allocation_exit(current);
319 JRT_END
320
321 // array allocation without zeroing
322 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread* current))
323 JRT_BLOCK;
324 #ifndef PRODUCT
325 SharedRuntime::_new_array_ctr++; // new array requires GC
326 #endif
327 assert(check_compiled_frame(current), "incorrect caller");
328
329 // Scavenge and allocate an instance.
330 oop result;
331
332 assert(array_type->is_typeArray_klass(), "should be called only for type array");
333 // The oopFactory likes to work with the element type.
334 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
335 result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD);
336
337 // Pass oops back through thread local storage. Our apparent type to Java
338 // is that we return an oop, but we can block on exit from this routine and
339 // a GC can trash the oop in C's return register. The generated stub will
340 // fetch the oop from TLS after any possible GC.
341 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
342 current->set_vm_result(result);
354 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
355 size_t hs_bytes = arrayOopDesc::base_offset_in_bytes(elem_type);
356 assert(is_aligned(hs_bytes, BytesPerInt), "must be 4 byte aligned");
357 HeapWord* obj = cast_from_oop<HeapWord*>(result);
358 if (!is_aligned(hs_bytes, BytesPerLong)) {
359 *reinterpret_cast<jint*>(reinterpret_cast<char*>(obj) + hs_bytes) = 0;
360 hs_bytes += BytesPerInt;
361 }
362
363 // Optimized zeroing.
364 assert(is_aligned(hs_bytes, BytesPerLong), "must be 8-byte aligned");
365 const size_t aligned_hs = hs_bytes / BytesPerLong;
366 Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs);
367 }
368
369 JRT_END
370
371 // Note: multianewarray for one dimension is handled inline by GraphKit::new_array.
372
373 // multianewarray for 2 dimensions
374 JRT_ENTRY(void, OptoRuntime::multianewarray2_C(Klass* elem_type, int len1, int len2, JavaThread* current))
375 #ifndef PRODUCT
376 SharedRuntime::_multi2_ctr++; // multianewarray for 1 dimension
377 #endif
378 assert(check_compiled_frame(current), "incorrect caller");
379 assert(elem_type->is_klass(), "not a class");
380 jint dims[2];
381 dims[0] = len1;
382 dims[1] = len2;
383 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
384 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD);
385 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
386 current->set_vm_result(obj);
387 JRT_END
388
389 // multianewarray for 3 dimensions
390 JRT_ENTRY(void, OptoRuntime::multianewarray3_C(Klass* elem_type, int len1, int len2, int len3, JavaThread* current))
391 #ifndef PRODUCT
392 SharedRuntime::_multi3_ctr++; // multianewarray for 1 dimension
393 #endif
394 assert(check_compiled_frame(current), "incorrect caller");
395 assert(elem_type->is_klass(), "not a class");
396 jint dims[3];
397 dims[0] = len1;
398 dims[1] = len2;
399 dims[2] = len3;
400 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
401 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD);
402 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
403 current->set_vm_result(obj);
404 JRT_END
405
406 // multianewarray for 4 dimensions
407 JRT_ENTRY(void, OptoRuntime::multianewarray4_C(Klass* elem_type, int len1, int len2, int len3, int len4, JavaThread* current))
408 #ifndef PRODUCT
409 SharedRuntime::_multi4_ctr++; // multianewarray for 1 dimension
410 #endif
411 assert(check_compiled_frame(current), "incorrect caller");
412 assert(elem_type->is_klass(), "not a class");
413 jint dims[4];
414 dims[0] = len1;
415 dims[1] = len2;
416 dims[2] = len3;
417 dims[3] = len4;
418 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
419 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD);
420 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
421 current->set_vm_result(obj);
422 JRT_END
423
424 // multianewarray for 5 dimensions
425 JRT_ENTRY(void, OptoRuntime::multianewarray5_C(Klass* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread* current))
426 #ifndef PRODUCT
427 SharedRuntime::_multi5_ctr++; // multianewarray for 1 dimension
428 #endif
429 assert(check_compiled_frame(current), "incorrect caller");
430 assert(elem_type->is_klass(), "not a class");
431 jint dims[5];
432 dims[0] = len1;
433 dims[1] = len2;
434 dims[2] = len3;
435 dims[3] = len4;
436 dims[4] = len5;
437 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
438 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD);
439 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
440 current->set_vm_result(obj);
441 JRT_END
442
443 JRT_ENTRY(void, OptoRuntime::multianewarrayN_C(Klass* elem_type, arrayOopDesc* dims, JavaThread* current))
444 assert(check_compiled_frame(current), "incorrect caller");
445 assert(elem_type->is_klass(), "not a class");
446 assert(oop(dims)->is_typeArray(), "not an array");
447
448 ResourceMark rm;
449 jint len = dims->length();
450 assert(len > 0, "Dimensions array should contain data");
451 jint *c_dims = NEW_RESOURCE_ARRAY(jint, len);
452 ArrayAccess<>::arraycopy_to_native<>(dims, typeArrayOopDesc::element_offset<jint>(0),
453 c_dims, len);
454
455 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
456 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(len, c_dims, THREAD);
457 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
458 current->set_vm_result(obj);
459 JRT_END
460
461 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notify_C(oopDesc* obj, JavaThread* current))
462
463 // Very few notify/notifyAll operations find any threads on the waitset, so
464 // the dominant fast-path is to simply return.
465 // Relatedly, it's critical that notify/notifyAll be fast in order to
466 // reduce lock hold times.
467 if (!SafepointSynchronize::is_synchronizing()) {
468 if (ObjectSynchronizer::quick_notify(obj, current, false)) {
469 return;
470 }
471 }
472
473 // This is the case the fast-path above isn't provisioned to handle.
474 // The fast-path is designed to handle frequently arising cases in an efficient manner.
475 // (The fast-path is just a degenerate variant of the slow-path).
476 // Perform the dreaded state transition and pass control into the slow-path.
477 JRT_BLOCK;
478 Handle h_obj(current, obj);
479 ObjectSynchronizer::notify(h_obj, CHECK);
480 JRT_BLOCK_END;
481 JRT_END
482
483 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notifyAll_C(oopDesc* obj, JavaThread* current))
484
485 if (!SafepointSynchronize::is_synchronizing() ) {
486 if (ObjectSynchronizer::quick_notify(obj, current, true)) {
487 return;
488 }
489 }
490
491 // This is the case the fast-path above isn't provisioned to handle.
492 // The fast-path is designed to handle frequently arising cases in an efficient manner.
493 // (The fast-path is just a degenerate variant of the slow-path).
494 // Perform the dreaded state transition and pass control into the slow-path.
495 JRT_BLOCK;
496 Handle h_obj(current, obj);
497 ObjectSynchronizer::notifyall(h_obj, CHECK);
498 JRT_BLOCK_END;
499 JRT_END
500
501 const TypeFunc *OptoRuntime::new_instance_Type() {
502 // create input type (domain)
503 const Type **fields = TypeTuple::fields(1);
1527 assert(reg >= 0 && reg < _last_Mach_Reg, "must be a machine register");
1528 switch (register_save_policy[reg]) {
1529 case 'C': return false; //SOC
1530 case 'E': return true ; //SOE
1531 case 'N': return false; //NS
1532 case 'A': return false; //AS
1533 }
1534 ShouldNotReachHere();
1535 return false;
1536 }
1537
1538 //-----------------------------------------------------------------------
1539 // Exceptions
1540 //
1541
1542 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg);
1543
1544 // The method is an entry that is always called by a C++ method not
1545 // directly from compiled code. Compiled code will call the C++ method following.
1546 // We can't allow async exception to be installed during exception processing.
1547 JRT_ENTRY_NO_ASYNC(address, OptoRuntime::handle_exception_C_helper(JavaThread* current, nmethod* &nm))
1548 // The frame we rethrow the exception to might not have been processed by the GC yet.
1549 // The stack watermark barrier takes care of detecting that and ensuring the frame
1550 // has updated oops.
1551 StackWatermarkSet::after_unwind(current);
1552
1553 // Do not confuse exception_oop with pending_exception. The exception_oop
1554 // is only used to pass arguments into the method. Not for general
1555 // exception handling. DO NOT CHANGE IT to use pending_exception, since
1556 // the runtime stubs checks this on exit.
1557 assert(current->exception_oop() != nullptr, "exception oop is found");
1558 address handler_address = nullptr;
1559
1560 Handle exception(current, current->exception_oop());
1561 address pc = current->exception_pc();
1562
1563 // Clear out the exception oop and pc since looking up an
1564 // exception handler can cause class loading, which might throw an
1565 // exception and those fields are expected to be clear during
1566 // normal bytecode execution.
1567 current->clear_exception_oop_and_pc();
1803 return caller_frame.is_deoptimized_frame();
1804 }
1805
1806
1807 const TypeFunc *OptoRuntime::register_finalizer_Type() {
1808 // create input type (domain)
1809 const Type **fields = TypeTuple::fields(1);
1810 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver
1811 // // The JavaThread* is passed to each routine as the last argument
1812 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
1813 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
1814
1815 // create result type (range)
1816 fields = TypeTuple::fields(0);
1817
1818 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1819
1820 return TypeFunc::make(domain,range);
1821 }
1822
1823 #if INCLUDE_JFR
1824 const TypeFunc *OptoRuntime::class_id_load_barrier_Type() {
1825 // create input type (domain)
1826 const Type **fields = TypeTuple::fields(1);
1827 fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS;
1828 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields);
1829
1830 // create result type (range)
1831 fields = TypeTuple::fields(0);
1832
1833 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields);
1834
1835 return TypeFunc::make(domain,range);
1836 }
1837 #endif
1838
1839 //-----------------------------------------------------------------------------
1840 // Dtrace support. entry and exit probes have the same signature
1841 const TypeFunc *OptoRuntime::dtrace_method_entry_exit_Type() {
1842 // create input type (domain)
1853 return TypeFunc::make(domain,range);
1854 }
1855
1856 const TypeFunc *OptoRuntime::dtrace_object_alloc_Type() {
1857 // create input type (domain)
1858 const Type **fields = TypeTuple::fields(2);
1859 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1860 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object
1861
1862 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1863
1864 // create result type (range)
1865 fields = TypeTuple::fields(0);
1866
1867 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1868
1869 return TypeFunc::make(domain,range);
1870 }
1871
1872
1873 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer_C(oopDesc* obj, JavaThread* current))
1874 assert(oopDesc::is_oop(obj), "must be a valid oop");
1875 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
1876 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
1877 JRT_END
1878
1879 //-----------------------------------------------------------------------------
1880
1881 NamedCounter * volatile OptoRuntime::_named_counters = nullptr;
1882
1883 //
1884 // dump the collected NamedCounters.
1885 //
1886 void OptoRuntime::print_named_counters() {
1887 int total_lock_count = 0;
1888 int eliminated_lock_count = 0;
1889
1890 NamedCounter* c = _named_counters;
1891 while (c) {
1892 if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) {
1893 int count = c->count();
1894 if (count > 0) {
1895 bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter;
1896 if (Verbose) {
1897 tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : "");
1898 }
1959 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
1960 trace_exception_counter++;
1961 stringStream tempst;
1962
1963 tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
1964 exception_oop->print_value_on(&tempst);
1965 tempst.print(" in ");
1966 CodeBlob* blob = CodeCache::find_blob(exception_pc);
1967 if (blob->is_nmethod()) {
1968 blob->as_nmethod()->method()->print_value_on(&tempst);
1969 } else if (blob->is_runtime_stub()) {
1970 tempst.print("<runtime-stub>");
1971 } else {
1972 tempst.print("<unknown>");
1973 }
1974 tempst.print(" at " INTPTR_FORMAT, p2i(exception_pc));
1975 tempst.print("]");
1976
1977 st->print_raw_cr(tempst.freeze());
1978 }
|
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 "precompiled.hpp"
26 #include "classfile/vmClasses.hpp"
27 #include "classfile/vmSymbols.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/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/objArrayKlass.hpp"
49 #include "oops/klass.inline.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/atomic.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/threadCritical.hpp"
77 #include "runtime/threadWXSetters.inline.hpp"
78 #include "runtime/vframe.hpp"
79 #include "runtime/vframeArray.hpp"
80 #include "runtime/vframe_hp.hpp"
81 #include "services/management.hpp"
82 #include "utilities/copy.hpp"
83 #include "utilities/preserveException.hpp"
84
85
86 // For debugging purposes:
87 // To force FullGCALot inside a runtime function, add the following two lines
88 //
89 // Universe::release_fullgc_alot_dummy();
90 // Universe::heap()->collect();
91 //
92 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
93
94
95 #define C2_BLOB_FIELD_DEFINE(name, type) \
96 type OptoRuntime:: BLOB_FIELD_NAME(name) = nullptr;
97 #define C2_STUB_FIELD_NAME(name) _ ## name ## _Java
98 #define C2_STUB_FIELD_DEFINE(name, f, t, r) \
99 address OptoRuntime:: C2_STUB_FIELD_NAME(name) = nullptr;
100 #define C2_JVMTI_STUB_FIELD_DEFINE(name) \
101 address OptoRuntime:: STUB_FIELD_NAME(name) = nullptr;
102 C2_STUBS_DO(C2_BLOB_FIELD_DEFINE, C2_STUB_FIELD_DEFINE, C2_JVMTI_STUB_FIELD_DEFINE)
103 #undef C2_BLOB_FIELD_DEFINE
104 #undef C2_STUB_FIELD_DEFINE
105 #undef C2_JVMTI_STUB_FIELD_DEFINE
106
107
108 #define C2_BLOB_NAME_DEFINE(name, type) "C2 Runtime " # name "_blob",
109 #define C2_STUB_NAME_DEFINE(name, f, t, r) "C2 Runtime " # name,
110 #define C2_JVMTI_STUB_NAME_DEFINE(name) "C2 Runtime " # name,
111 const char* OptoRuntime::_stub_names[] = {
112 C2_STUBS_DO(C2_BLOB_NAME_DEFINE, C2_STUB_NAME_DEFINE, C2_JVMTI_STUB_NAME_DEFINE)
113 };
114 #undef C2_BLOB_NAME_DEFINE
115 #undef C2_STUB_NAME_DEFINE
116 #undef C2_JVMTI_STUB_NAME_DEFINE
117
118 address OptoRuntime::_vtable_must_compile_Java = nullptr;
119
120 PerfCounter* _perf_OptoRuntime_class_init_barrier_redundant_count = nullptr;
121
122 // This should be called in an assertion at the start of OptoRuntime routines
123 // which are entered from compiled code (all of them)
124 #ifdef ASSERT
125 static bool check_compiled_frame(JavaThread* thread) {
126 assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
127 RegisterMap map(thread,
128 RegisterMap::UpdateMap::skip,
129 RegisterMap::ProcessFrames::include,
130 RegisterMap::WalkContinuation::skip);
131 frame caller = thread->last_frame().sender(&map);
132 assert(caller.is_compiled_frame(), "not being called from compiled like code");
133 return true;
134 }
135 #endif // ASSERT
136
137 /*
138 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, return_pc) \
139 var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, return_pc); \
140 if (var == nullptr) { return false; }
141 */
166 C2_STUB_NAME(name), \
167 fancy_jump, \
168 pass_tls, \
169 pass_retpc); \
170 if (C2_STUB_FIELD_NAME(name) == nullptr) { return false; } \
171
172 #define C2_JVMTI_STUB_C_FUNC(name) CAST_FROM_FN_PTR(address, SharedRuntime::name)
173
174 #define GEN_C2_JVMTI_STUB(name) \
175 STUB_FIELD_NAME(name) = \
176 generate_stub(env, \
177 notify_jvmti_vthread_Type, \
178 C2_JVMTI_STUB_C_FUNC(name), \
179 C2_STUB_NAME(name), \
180 0, \
181 true, \
182 false); \
183 if (STUB_FIELD_NAME(name) == nullptr) { return false; } \
184
185 bool OptoRuntime::generate(ciEnv* env) {
186 init_counters();
187
188 C2_STUBS_DO(GEN_C2_BLOB, GEN_C2_STUB, GEN_C2_JVMTI_STUB)
189
190 return true;
191 }
192
193 #undef GEN_C2_BLOB
194
195 #undef C2_STUB_FIELD_NAME
196 #undef C2_STUB_TYPEFUNC
197 #undef C2_STUB_C_FUNC
198 #undef C2_STUB_NAME
199 #undef GEN_C2_STUB
200
201 #undef C2_JVMTI_STUB_C_FUNC
202 #undef GEN_C2_JVMTI_STUB
203 // #undef gen
204
205
206 // Helper method to do generation of RunTimeStub's
207 address OptoRuntime::generate_stub(ciEnv* env,
208 TypeFunc_generator gen, address C_function,
209 const char *name, int is_fancy_jump,
210 bool pass_tls,
211 bool return_pc) {
212
213 // Matching the default directive, we currently have no method to match.
214 DirectiveSet* directive = DirectivesStack::getDefaultDirective(CompilerThread::current()->compiler());
215 ResourceMark rm;
216 Compile C(env, gen, C_function, name, is_fancy_jump, pass_tls, return_pc, directive);
217 DirectivesStack::release(directive);
218 return C.stub_entry_point();
219 }
220
221 const char* OptoRuntime::stub_name(address entry) {
222 #ifndef PRODUCT
223 CodeBlob* cb = CodeCache::find_blob(entry);
224 RuntimeStub* rs =(RuntimeStub *)cb;
225 assert(rs != nullptr && rs->is_runtime_stub(), "not a runtime stub");
226 return rs->name();
227 #else
228 // Fast implementation for product mode (maybe it should be inlined too)
229 return "runtime stub";
230 #endif
231 }
232
233 // local methods passed as arguments to stub generator that forward
234 // control to corresponding JRT methods of SharedRuntime
237 oopDesc* dest, jint dest_pos,
238 jint length, JavaThread* thread) {
239 SharedRuntime::slow_arraycopy_C(src, src_pos, dest, dest_pos, length, thread);
240 }
241
242 void OptoRuntime::complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current) {
243 SharedRuntime::complete_monitor_locking_C(obj, lock, current);
244 }
245
246
247 //=============================================================================
248 // Opto compiler runtime routines
249 //=============================================================================
250
251
252 //=============================allocation======================================
253 // We failed the fast-path allocation. Now we need to do a scavenge or GC
254 // and try allocation again.
255
256 // object allocation
257 JRT_BLOCK_ENTRY_PROF(void, OptoRuntime, new_instance_C, OptoRuntime::new_instance_C(Klass* klass, JavaThread* current))
258 JRT_BLOCK;
259 #ifndef PRODUCT
260 SharedRuntime::_new_instance_ctr++; // new instance requires GC
261 #endif
262 assert(check_compiled_frame(current), "incorrect caller");
263
264 // These checks are cheap to make and support reflective allocation.
265 int lh = klass->layout_helper();
266 if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
267 Handle holder(current, klass->klass_holder()); // keep the klass alive
268 klass->check_valid_for_instantiation(false, THREAD);
269 if (!HAS_PENDING_EXCEPTION) {
270 InstanceKlass::cast(klass)->initialize(THREAD);
271 }
272 }
273
274 if (!HAS_PENDING_EXCEPTION) {
275 // Scavenge and allocate an instance.
276 Handle holder(current, klass->klass_holder()); // keep the klass alive
277 oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
278 current->set_vm_result(result);
279
280 // Pass oops back through thread local storage. Our apparent type to Java
281 // is that we return an oop, but we can block on exit from this routine and
282 // a GC can trash the oop in C's return register. The generated stub will
283 // fetch the oop from TLS after any possible GC.
284 }
285
286 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
287 JRT_BLOCK_END;
288
289 // inform GC that we won't do card marks for initializing writes.
290 SharedRuntime::on_slowpath_allocation_exit(current);
291 JRT_END
292
293
294 // array allocation
295 JRT_BLOCK_ENTRY_PROF(void, OptoRuntime, new_array_C, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread* current))
296 JRT_BLOCK;
297 #ifndef PRODUCT
298 SharedRuntime::_new_array_ctr++; // new array requires GC
299 #endif
300 assert(check_compiled_frame(current), "incorrect caller");
301
302 // Scavenge and allocate an instance.
303 oop result;
304
305 if (array_type->is_typeArray_klass()) {
306 // The oopFactory likes to work with the element type.
307 // (We could bypass the oopFactory, since it doesn't add much value.)
308 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
309 result = oopFactory::new_typeArray(elem_type, len, THREAD);
310 } else {
311 // Although the oopFactory likes to work with the elem_type,
312 // the compiler prefers the array_type, since it must already have
313 // that latter value in hand for the fast path.
314 Handle holder(current, array_type->klass_holder()); // keep the array klass alive
315 Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass();
316 result = oopFactory::new_objArray(elem_type, len, THREAD);
317 }
318
319 // Pass oops back through thread local storage. Our apparent type to Java
320 // is that we return an oop, but we can block on exit from this routine and
321 // a GC can trash the oop in C's return register. The generated stub will
322 // fetch the oop from TLS after any possible GC.
323 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
324 current->set_vm_result(result);
325 JRT_BLOCK_END;
326
327 // inform GC that we won't do card marks for initializing writes.
328 SharedRuntime::on_slowpath_allocation_exit(current);
329 JRT_END
330
331 // array allocation without zeroing
332 JRT_BLOCK_ENTRY_PROF(void, OptoRuntime, new_array_nozero_C, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread* current))
333 JRT_BLOCK;
334 #ifndef PRODUCT
335 SharedRuntime::_new_array_ctr++; // new array requires GC
336 #endif
337 assert(check_compiled_frame(current), "incorrect caller");
338
339 // Scavenge and allocate an instance.
340 oop result;
341
342 assert(array_type->is_typeArray_klass(), "should be called only for type array");
343 // The oopFactory likes to work with the element type.
344 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
345 result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD);
346
347 // Pass oops back through thread local storage. Our apparent type to Java
348 // is that we return an oop, but we can block on exit from this routine and
349 // a GC can trash the oop in C's return register. The generated stub will
350 // fetch the oop from TLS after any possible GC.
351 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
352 current->set_vm_result(result);
364 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
365 size_t hs_bytes = arrayOopDesc::base_offset_in_bytes(elem_type);
366 assert(is_aligned(hs_bytes, BytesPerInt), "must be 4 byte aligned");
367 HeapWord* obj = cast_from_oop<HeapWord*>(result);
368 if (!is_aligned(hs_bytes, BytesPerLong)) {
369 *reinterpret_cast<jint*>(reinterpret_cast<char*>(obj) + hs_bytes) = 0;
370 hs_bytes += BytesPerInt;
371 }
372
373 // Optimized zeroing.
374 assert(is_aligned(hs_bytes, BytesPerLong), "must be 8-byte aligned");
375 const size_t aligned_hs = hs_bytes / BytesPerLong;
376 Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs);
377 }
378
379 JRT_END
380
381 // Note: multianewarray for one dimension is handled inline by GraphKit::new_array.
382
383 // multianewarray for 2 dimensions
384 JRT_ENTRY_PROF(void, OptoRuntime, multianewarray2_C, OptoRuntime::multianewarray2_C(Klass* elem_type, int len1, int len2, JavaThread* current))
385 #ifndef PRODUCT
386 SharedRuntime::_multi2_ctr++; // multianewarray for 1 dimension
387 #endif
388 assert(check_compiled_frame(current), "incorrect caller");
389 assert(elem_type->is_klass(), "not a class");
390 jint dims[2];
391 dims[0] = len1;
392 dims[1] = len2;
393 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
394 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD);
395 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
396 current->set_vm_result(obj);
397 JRT_END
398
399 // multianewarray for 3 dimensions
400 JRT_ENTRY_PROF(void, OptoRuntime, multianewarray3_C, OptoRuntime::multianewarray3_C(Klass* elem_type, int len1, int len2, int len3, JavaThread* current))
401 #ifndef PRODUCT
402 SharedRuntime::_multi3_ctr++; // multianewarray for 1 dimension
403 #endif
404 assert(check_compiled_frame(current), "incorrect caller");
405 assert(elem_type->is_klass(), "not a class");
406 jint dims[3];
407 dims[0] = len1;
408 dims[1] = len2;
409 dims[2] = len3;
410 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
411 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD);
412 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
413 current->set_vm_result(obj);
414 JRT_END
415
416 // multianewarray for 4 dimensions
417 JRT_ENTRY_PROF(void, OptoRuntime, multianewarray4_C, OptoRuntime::multianewarray4_C(Klass* elem_type, int len1, int len2, int len3, int len4, JavaThread* current))
418 #ifndef PRODUCT
419 SharedRuntime::_multi4_ctr++; // multianewarray for 1 dimension
420 #endif
421 assert(check_compiled_frame(current), "incorrect caller");
422 assert(elem_type->is_klass(), "not a class");
423 jint dims[4];
424 dims[0] = len1;
425 dims[1] = len2;
426 dims[2] = len3;
427 dims[3] = len4;
428 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
429 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD);
430 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
431 current->set_vm_result(obj);
432 JRT_END
433
434 // multianewarray for 5 dimensions
435 JRT_ENTRY(void, OptoRuntime::multianewarray5_C(Klass* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread* current))
436 #ifndef PRODUCT
437 SharedRuntime::_multi5_ctr++; // multianewarray for 1 dimension
438 #endif
439 assert(check_compiled_frame(current), "incorrect caller");
440 assert(elem_type->is_klass(), "not a class");
441 jint dims[5];
442 dims[0] = len1;
443 dims[1] = len2;
444 dims[2] = len3;
445 dims[3] = len4;
446 dims[4] = len5;
447 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
448 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD);
449 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
450 current->set_vm_result(obj);
451 JRT_END
452
453 JRT_ENTRY_PROF(void, OptoRuntime, multianewarrayN_C, OptoRuntime::multianewarrayN_C(Klass* elem_type, arrayOopDesc* dims, JavaThread* current))
454 assert(check_compiled_frame(current), "incorrect caller");
455 assert(elem_type->is_klass(), "not a class");
456 assert(oop(dims)->is_typeArray(), "not an array");
457
458 ResourceMark rm;
459 jint len = dims->length();
460 assert(len > 0, "Dimensions array should contain data");
461 jint *c_dims = NEW_RESOURCE_ARRAY(jint, len);
462 ArrayAccess<>::arraycopy_to_native<>(dims, typeArrayOopDesc::element_offset<jint>(0),
463 c_dims, len);
464
465 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
466 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(len, c_dims, THREAD);
467 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
468 current->set_vm_result(obj);
469 JRT_END
470
471 JRT_BLOCK_ENTRY_PROF(void, OptoRuntime, monitor_notify_C, OptoRuntime::monitor_notify_C(oopDesc* obj, JavaThread* current))
472
473 // Very few notify/notifyAll operations find any threads on the waitset, so
474 // the dominant fast-path is to simply return.
475 // Relatedly, it's critical that notify/notifyAll be fast in order to
476 // reduce lock hold times.
477 if (!SafepointSynchronize::is_synchronizing()) {
478 if (ObjectSynchronizer::quick_notify(obj, current, false)) {
479 return;
480 }
481 }
482
483 // This is the case the fast-path above isn't provisioned to handle.
484 // The fast-path is designed to handle frequently arising cases in an efficient manner.
485 // (The fast-path is just a degenerate variant of the slow-path).
486 // Perform the dreaded state transition and pass control into the slow-path.
487 JRT_BLOCK;
488 Handle h_obj(current, obj);
489 ObjectSynchronizer::notify(h_obj, CHECK);
490 JRT_BLOCK_END;
491 JRT_END
492
493 JRT_BLOCK_ENTRY_PROF(void, OptoRuntime, monitor_notifyAll_C, OptoRuntime::monitor_notifyAll_C(oopDesc* obj, JavaThread* current))
494
495 if (!SafepointSynchronize::is_synchronizing() ) {
496 if (ObjectSynchronizer::quick_notify(obj, current, true)) {
497 return;
498 }
499 }
500
501 // This is the case the fast-path above isn't provisioned to handle.
502 // The fast-path is designed to handle frequently arising cases in an efficient manner.
503 // (The fast-path is just a degenerate variant of the slow-path).
504 // Perform the dreaded state transition and pass control into the slow-path.
505 JRT_BLOCK;
506 Handle h_obj(current, obj);
507 ObjectSynchronizer::notifyall(h_obj, CHECK);
508 JRT_BLOCK_END;
509 JRT_END
510
511 const TypeFunc *OptoRuntime::new_instance_Type() {
512 // create input type (domain)
513 const Type **fields = TypeTuple::fields(1);
1537 assert(reg >= 0 && reg < _last_Mach_Reg, "must be a machine register");
1538 switch (register_save_policy[reg]) {
1539 case 'C': return false; //SOC
1540 case 'E': return true ; //SOE
1541 case 'N': return false; //NS
1542 case 'A': return false; //AS
1543 }
1544 ShouldNotReachHere();
1545 return false;
1546 }
1547
1548 //-----------------------------------------------------------------------
1549 // Exceptions
1550 //
1551
1552 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg);
1553
1554 // The method is an entry that is always called by a C++ method not
1555 // directly from compiled code. Compiled code will call the C++ method following.
1556 // We can't allow async exception to be installed during exception processing.
1557 JRT_ENTRY_NO_ASYNC_PROF(address, OptoRuntime, handle_exception_C_helper, OptoRuntime::handle_exception_C_helper(JavaThread* current, nmethod* &nm))
1558 // The frame we rethrow the exception to might not have been processed by the GC yet.
1559 // The stack watermark barrier takes care of detecting that and ensuring the frame
1560 // has updated oops.
1561 StackWatermarkSet::after_unwind(current);
1562
1563 // Do not confuse exception_oop with pending_exception. The exception_oop
1564 // is only used to pass arguments into the method. Not for general
1565 // exception handling. DO NOT CHANGE IT to use pending_exception, since
1566 // the runtime stubs checks this on exit.
1567 assert(current->exception_oop() != nullptr, "exception oop is found");
1568 address handler_address = nullptr;
1569
1570 Handle exception(current, current->exception_oop());
1571 address pc = current->exception_pc();
1572
1573 // Clear out the exception oop and pc since looking up an
1574 // exception handler can cause class loading, which might throw an
1575 // exception and those fields are expected to be clear during
1576 // normal bytecode execution.
1577 current->clear_exception_oop_and_pc();
1813 return caller_frame.is_deoptimized_frame();
1814 }
1815
1816
1817 const TypeFunc *OptoRuntime::register_finalizer_Type() {
1818 // create input type (domain)
1819 const Type **fields = TypeTuple::fields(1);
1820 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver
1821 // // The JavaThread* is passed to each routine as the last argument
1822 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
1823 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
1824
1825 // create result type (range)
1826 fields = TypeTuple::fields(0);
1827
1828 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1829
1830 return TypeFunc::make(domain,range);
1831 }
1832
1833 const TypeFunc *OptoRuntime::class_init_barrier_Type() {
1834 // create input type (domain)
1835 const Type** fields = TypeTuple::fields(1);
1836 fields[TypeFunc::Parms+0] = TypeKlassPtr::NOTNULL;
1837 // // The JavaThread* is passed to each routine as the last argument
1838 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
1839 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+1, fields);
1840
1841 // create result type (range)
1842 fields = TypeTuple::fields(0);
1843 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
1844 return TypeFunc::make(domain,range);
1845 }
1846
1847 #if INCLUDE_JFR
1848 const TypeFunc *OptoRuntime::class_id_load_barrier_Type() {
1849 // create input type (domain)
1850 const Type **fields = TypeTuple::fields(1);
1851 fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS;
1852 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields);
1853
1854 // create result type (range)
1855 fields = TypeTuple::fields(0);
1856
1857 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields);
1858
1859 return TypeFunc::make(domain,range);
1860 }
1861 #endif
1862
1863 //-----------------------------------------------------------------------------
1864 // Dtrace support. entry and exit probes have the same signature
1865 const TypeFunc *OptoRuntime::dtrace_method_entry_exit_Type() {
1866 // create input type (domain)
1877 return TypeFunc::make(domain,range);
1878 }
1879
1880 const TypeFunc *OptoRuntime::dtrace_object_alloc_Type() {
1881 // create input type (domain)
1882 const Type **fields = TypeTuple::fields(2);
1883 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1884 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object
1885
1886 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1887
1888 // create result type (range)
1889 fields = TypeTuple::fields(0);
1890
1891 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1892
1893 return TypeFunc::make(domain,range);
1894 }
1895
1896
1897 JRT_ENTRY_NO_ASYNC_PROF(void, OptoRuntime, register_finalizer_C, OptoRuntime::register_finalizer_C(oopDesc* obj, JavaThread* current))
1898 assert(oopDesc::is_oop(obj), "must be a valid oop");
1899 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
1900 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
1901 JRT_END
1902
1903 JRT_ENTRY_NO_ASYNC_PROF(void, OptoRuntime, class_init_barrier_C, OptoRuntime::class_init_barrier_C(Klass* k, JavaThread* current))
1904 InstanceKlass* ik = InstanceKlass::cast(k);
1905 if (ik->should_be_initialized()) {
1906 ik->initialize(CHECK);
1907 } else if (UsePerfData) {
1908 _perf_OptoRuntime_class_init_barrier_redundant_count->inc();
1909 }
1910 JRT_END
1911
1912 //-----------------------------------------------------------------------------
1913
1914 NamedCounter * volatile OptoRuntime::_named_counters = nullptr;
1915
1916 //
1917 // dump the collected NamedCounters.
1918 //
1919 void OptoRuntime::print_named_counters() {
1920 int total_lock_count = 0;
1921 int eliminated_lock_count = 0;
1922
1923 NamedCounter* c = _named_counters;
1924 while (c) {
1925 if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) {
1926 int count = c->count();
1927 if (count > 0) {
1928 bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter;
1929 if (Verbose) {
1930 tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : "");
1931 }
1992 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
1993 trace_exception_counter++;
1994 stringStream tempst;
1995
1996 tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
1997 exception_oop->print_value_on(&tempst);
1998 tempst.print(" in ");
1999 CodeBlob* blob = CodeCache::find_blob(exception_pc);
2000 if (blob->is_nmethod()) {
2001 blob->as_nmethod()->method()->print_value_on(&tempst);
2002 } else if (blob->is_runtime_stub()) {
2003 tempst.print("<runtime-stub>");
2004 } else {
2005 tempst.print("<unknown>");
2006 }
2007 tempst.print(" at " INTPTR_FORMAT, p2i(exception_pc));
2008 tempst.print("]");
2009
2010 st->print_raw_cr(tempst.freeze());
2011 }
2012
2013 #define DO_COUNTERS2(macro2, macro1) \
2014 macro2(OptoRuntime, new_instance_C) \
2015 macro2(OptoRuntime, new_array_C) \
2016 macro2(OptoRuntime, new_array_nozero_C) \
2017 macro2(OptoRuntime, multianewarray2_C) \
2018 macro2(OptoRuntime, multianewarray3_C) \
2019 macro2(OptoRuntime, multianewarray4_C) \
2020 macro2(OptoRuntime, multianewarrayN_C) \
2021 macro2(OptoRuntime, monitor_notify_C) \
2022 macro2(OptoRuntime, monitor_notifyAll_C) \
2023 macro2(OptoRuntime, handle_exception_C_helper) \
2024 macro2(OptoRuntime, register_finalizer_C) \
2025 macro2(OptoRuntime, class_init_barrier_C) \
2026 macro1(OptoRuntime, class_init_barrier_redundant)
2027
2028 #define INIT_COUNTER_TIME_AND_CNT(sub, name) \
2029 NEWPERFTICKCOUNTERS(_perf_##sub##_##name##_timer, SUN_CI, #sub "::" #name); \
2030 NEWPERFEVENTCOUNTER(_perf_##sub##_##name##_count, SUN_CI, #sub "::" #name "_count");
2031
2032 #define INIT_COUNTER_CNT(sub, name) \
2033 NEWPERFEVENTCOUNTER(_perf_##sub##_##name##_count, SUN_CI, #sub "::" #name "_count");
2034
2035 void OptoRuntime::init_counters() {
2036 assert(CompilerConfig::is_c2_enabled(), "");
2037
2038 if (UsePerfData) {
2039 EXCEPTION_MARK;
2040
2041 DO_COUNTERS2(INIT_COUNTER_TIME_AND_CNT, INIT_COUNTER_CNT)
2042
2043 if (HAS_PENDING_EXCEPTION) {
2044 vm_exit_during_initialization("jvm_perf_init failed unexpectedly");
2045 }
2046 }
2047 }
2048 #undef INIT_COUNTER_TIME_AND_CNT
2049 #undef INIT_COUNTER_CNT
2050
2051 #define PRINT_COUNTER_TIME_AND_CNT(sub, name) { \
2052 jlong count = _perf_##sub##_##name##_count->get_value(); \
2053 if (count > 0) { \
2054 st->print_cr(" %-50s = " JLONG_FORMAT_W(6) "us (elapsed) " JLONG_FORMAT_W(6) "us (thread) (" JLONG_FORMAT_W(5) " events)", #sub "::" #name, \
2055 _perf_##sub##_##name##_timer->elapsed_counter_value_us(), \
2056 _perf_##sub##_##name##_timer->thread_counter_value_us(), \
2057 count); \
2058 }}
2059
2060 #define PRINT_COUNTER_CNT(sub, name) { \
2061 jlong count = _perf_##sub##_##name##_count->get_value(); \
2062 if (count > 0) { \
2063 st->print_cr(" %-30s = " JLONG_FORMAT_W(5) " events", #name, count); \
2064 }}
2065
2066 void OptoRuntime::print_counters_on(outputStream* st) {
2067 if (UsePerfData && ProfileRuntimeCalls && CompilerConfig::is_c2_enabled()) {
2068 DO_COUNTERS2(PRINT_COUNTER_TIME_AND_CNT, PRINT_COUNTER_CNT)
2069 } else {
2070 st->print_cr(" OptoRuntime: no info (%s is disabled)",
2071 (!CompilerConfig::is_c2_enabled() ? "C2" : (UsePerfData ? "ProfileRuntimeCalls" : "UsePerfData")));
2072 }
2073 }
2074
2075 #undef PRINT_COUNTER_TIME_AND_CNT
2076 #undef PRINT_COUNTER_CNT
2077 #undef DO_COUNTERS2
|