1 /*
2 * Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/vmClasses.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "code/codeCache.hpp"
29 #include "code/compiledMethod.inline.hpp"
30 #include "code/compiledIC.hpp"
31 #include "code/icBuffer.hpp"
32 #include "code/nmethod.hpp"
33 #include "code/pcDesc.hpp"
34 #include "code/scopeDesc.hpp"
35 #include "code/vtableStubs.hpp"
36 #include "compiler/compileBroker.hpp"
37 #include "compiler/oopMap.hpp"
38 #include "gc/g1/heapRegion.hpp"
39 #include "gc/shared/barrierSet.hpp"
40 #include "gc/shared/collectedHeap.hpp"
41 #include "gc/shared/gcLocker.hpp"
42 #include "interpreter/bytecode.hpp"
43 #include "interpreter/interpreter.hpp"
44 #include "interpreter/linkResolver.hpp"
45 #include "logging/log.hpp"
46 #include "logging/logStream.hpp"
47 #include "memory/oopFactory.hpp"
48 #include "memory/resourceArea.hpp"
49 #include "oops/objArrayKlass.hpp"
50 #include "oops/klass.inline.hpp"
51 #include "oops/oop.inline.hpp"
52 #include "oops/typeArrayOop.inline.hpp"
53 #include "opto/ad.hpp"
54 #include "opto/addnode.hpp"
55 #include "opto/callnode.hpp"
56 #include "opto/cfgnode.hpp"
57 #include "opto/graphKit.hpp"
58 #include "opto/machnode.hpp"
59 #include "opto/matcher.hpp"
60 #include "opto/memnode.hpp"
61 #include "opto/mulnode.hpp"
62 #include "opto/output.hpp"
63 #include "opto/runtime.hpp"
64 #include "opto/subnode.hpp"
65 #include "prims/jvmtiExport.hpp"
66 #include "runtime/atomic.hpp"
67 #include "runtime/frame.inline.hpp"
68 #include "runtime/handles.inline.hpp"
69 #include "runtime/interfaceSupport.inline.hpp"
70 #include "runtime/javaCalls.hpp"
71 #include "runtime/sharedRuntime.hpp"
72 #include "runtime/signature.hpp"
73 #include "runtime/stackWatermarkSet.hpp"
74 #include "runtime/synchronizer.hpp"
75 #include "runtime/threadCritical.hpp"
76 #include "runtime/threadWXSetters.inline.hpp"
77 #include "runtime/vframe.hpp"
78 #include "runtime/vframeArray.hpp"
79 #include "runtime/vframe_hp.hpp"
80 #include "utilities/copy.hpp"
81 #include "utilities/preserveException.hpp"
82
83
84 // For debugging purposes:
85 // To force FullGCALot inside a runtime function, add the following two lines
86 //
87 // Universe::release_fullgc_alot_dummy();
88 // MarkSweep::invoke(0, "Debugging");
89 //
90 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
91
92
93
94
95 // Compiled code entry points
96 address OptoRuntime::_new_instance_Java = nullptr;
97 address OptoRuntime::_new_array_Java = nullptr;
98 address OptoRuntime::_new_array_nozero_Java = nullptr;
99 address OptoRuntime::_multianewarray2_Java = nullptr;
100 address OptoRuntime::_multianewarray3_Java = nullptr;
101 address OptoRuntime::_multianewarray4_Java = nullptr;
102 address OptoRuntime::_multianewarray5_Java = nullptr;
103 address OptoRuntime::_multianewarrayN_Java = nullptr;
104 address OptoRuntime::_vtable_must_compile_Java = nullptr;
105 address OptoRuntime::_complete_monitor_locking_Java = nullptr;
106 address OptoRuntime::_monitor_notify_Java = nullptr;
107 address OptoRuntime::_monitor_notifyAll_Java = nullptr;
108 address OptoRuntime::_rethrow_Java = nullptr;
109
110 address OptoRuntime::_slow_arraycopy_Java = nullptr;
111 address OptoRuntime::_register_finalizer_Java = nullptr;
112 #if INCLUDE_JVMTI
113 address OptoRuntime::_notify_jvmti_vthread_start = nullptr;
114 address OptoRuntime::_notify_jvmti_vthread_end = nullptr;
115 address OptoRuntime::_notify_jvmti_vthread_mount = nullptr;
116 address OptoRuntime::_notify_jvmti_vthread_unmount = nullptr;
117 #endif
118
119 ExceptionBlob* OptoRuntime::_exception_blob;
120
121 // This should be called in an assertion at the start of OptoRuntime routines
122 // which are entered from compiled code (all of them)
123 #ifdef ASSERT
124 static bool check_compiled_frame(JavaThread* thread) {
125 assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
126 RegisterMap map(thread,
127 RegisterMap::UpdateMap::skip,
128 RegisterMap::ProcessFrames::include,
129 RegisterMap::WalkContinuation::skip);
130 frame caller = thread->last_frame().sender(&map);
131 assert(caller.is_compiled_frame(), "not being called from compiled like code");
132 return true;
133 }
134 #endif // ASSERT
135
136
137 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, return_pc) \
138 var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, return_pc); \
139 if (var == nullptr) { return false; }
140
141 bool OptoRuntime::generate(ciEnv* env) {
142
143 generate_exception_blob();
144
145 // Note: tls: Means fetching the return oop out of the thread-local storage
146 //
147 // variable/name type-function-gen , runtime method ,fncy_jp, tls,retpc
148 // -------------------------------------------------------------------------------------------------------------------------------
149 gen(env, _new_instance_Java , new_instance_Type , new_instance_C , 0 , true, false);
150 gen(env, _new_array_Java , new_array_Type , new_array_C , 0 , true, false);
151 gen(env, _new_array_nozero_Java , new_array_Type , new_array_nozero_C , 0 , true, false);
152 gen(env, _multianewarray2_Java , multianewarray2_Type , multianewarray2_C , 0 , true, false);
153 gen(env, _multianewarray3_Java , multianewarray3_Type , multianewarray3_C , 0 , true, false);
154 gen(env, _multianewarray4_Java , multianewarray4_Type , multianewarray4_C , 0 , true, false);
155 gen(env, _multianewarray5_Java , multianewarray5_Type , multianewarray5_C , 0 , true, false);
156 gen(env, _multianewarrayN_Java , multianewarrayN_Type , multianewarrayN_C , 0 , true, false);
157 #if INCLUDE_JVMTI
158 gen(env, _notify_jvmti_vthread_start , notify_jvmti_vthread_Type , SharedRuntime::notify_jvmti_vthread_start, 0, true, false);
159 gen(env, _notify_jvmti_vthread_end , notify_jvmti_vthread_Type , SharedRuntime::notify_jvmti_vthread_end, 0, true, false);
160 gen(env, _notify_jvmti_vthread_mount , notify_jvmti_vthread_Type , SharedRuntime::notify_jvmti_vthread_mount, 0, true, false);
161 gen(env, _notify_jvmti_vthread_unmount , notify_jvmti_vthread_Type , SharedRuntime::notify_jvmti_vthread_unmount, 0, true, false);
162 #endif
163 gen(env, _complete_monitor_locking_Java , complete_monitor_enter_Type , SharedRuntime::complete_monitor_locking_C, 0, false, false);
164 gen(env, _monitor_notify_Java , monitor_notify_Type , monitor_notify_C , 0 , false, false);
165 gen(env, _monitor_notifyAll_Java , monitor_notify_Type , monitor_notifyAll_C , 0 , false, false);
166 gen(env, _rethrow_Java , rethrow_Type , rethrow_C , 2 , true , true );
167
168 gen(env, _slow_arraycopy_Java , slow_arraycopy_Type , SharedRuntime::slow_arraycopy_C , 0 , false, false);
169 gen(env, _register_finalizer_Java , register_finalizer_Type , register_finalizer , 0 , false, false);
170
171 return true;
172 }
173
174 #undef gen
175
176
177 // Helper method to do generation of RunTimeStub's
178 address OptoRuntime::generate_stub(ciEnv* env,
179 TypeFunc_generator gen, address C_function,
180 const char *name, int is_fancy_jump,
181 bool pass_tls,
182 bool return_pc) {
183
184 // Matching the default directive, we currently have no method to match.
185 DirectiveSet* directive = DirectivesStack::getDefaultDirective(CompileBroker::compiler(CompLevel_full_optimization));
186 ResourceMark rm;
187 Compile C(env, gen, C_function, name, is_fancy_jump, pass_tls, return_pc, directive);
188 DirectivesStack::release(directive);
189 return C.stub_entry_point();
190 }
191
192 const char* OptoRuntime::stub_name(address entry) {
193 #ifndef PRODUCT
194 CodeBlob* cb = CodeCache::find_blob(entry);
195 RuntimeStub* rs =(RuntimeStub *)cb;
196 assert(rs != nullptr && rs->is_runtime_stub(), "not a runtime stub");
197 return rs->name();
198 #else
199 // Fast implementation for product mode (maybe it should be inlined too)
200 return "runtime stub";
201 #endif
202 }
203
204
205 //=============================================================================
206 // Opto compiler runtime routines
207 //=============================================================================
208
209
210 //=============================allocation======================================
211 // We failed the fast-path allocation. Now we need to do a scavenge or GC
212 // and try allocation again.
213
214 // object allocation
215 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, JavaThread* current))
216 JRT_BLOCK;
217 #ifndef PRODUCT
218 SharedRuntime::_new_instance_ctr++; // new instance requires GC
219 #endif
220 assert(check_compiled_frame(current), "incorrect caller");
221
222 // These checks are cheap to make and support reflective allocation.
223 int lh = klass->layout_helper();
224 if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
225 Handle holder(current, klass->klass_holder()); // keep the klass alive
226 klass->check_valid_for_instantiation(false, THREAD);
227 if (!HAS_PENDING_EXCEPTION) {
228 InstanceKlass::cast(klass)->initialize(THREAD);
229 }
230 }
231
232 if (!HAS_PENDING_EXCEPTION) {
233 // Scavenge and allocate an instance.
234 Handle holder(current, klass->klass_holder()); // keep the klass alive
235 oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
236 current->set_vm_result(result);
237
238 // Pass oops back through thread local storage. Our apparent type to Java
239 // is that we return an oop, but we can block on exit from this routine and
240 // a GC can trash the oop in C's return register. The generated stub will
241 // fetch the oop from TLS after any possible GC.
242 }
243
244 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
245 JRT_BLOCK_END;
246
247 // inform GC that we won't do card marks for initializing writes.
248 SharedRuntime::on_slowpath_allocation_exit(current);
249 JRT_END
250
251
252 // array allocation
253 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread* current))
254 JRT_BLOCK;
255 #ifndef PRODUCT
256 SharedRuntime::_new_array_ctr++; // new array requires GC
257 #endif
258 assert(check_compiled_frame(current), "incorrect caller");
259
260 // Scavenge and allocate an instance.
261 oop result;
262
263 if (array_type->is_typeArray_klass()) {
264 // The oopFactory likes to work with the element type.
265 // (We could bypass the oopFactory, since it doesn't add much value.)
266 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
267 result = oopFactory::new_typeArray(elem_type, len, THREAD);
268 } else {
269 // Although the oopFactory likes to work with the elem_type,
270 // the compiler prefers the array_type, since it must already have
271 // that latter value in hand for the fast path.
272 Handle holder(current, array_type->klass_holder()); // keep the array klass alive
273 Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass();
274 result = oopFactory::new_objArray(elem_type, len, THREAD);
275 }
276
277 // Pass oops back through thread local storage. Our apparent type to Java
278 // is that we return an oop, but we can block on exit from this routine and
279 // a GC can trash the oop in C's return register. The generated stub will
280 // fetch the oop from TLS after any possible GC.
281 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
282 current->set_vm_result(result);
283 JRT_BLOCK_END;
284
285 // inform GC that we won't do card marks for initializing writes.
286 SharedRuntime::on_slowpath_allocation_exit(current);
287 JRT_END
288
289 // array allocation without zeroing
290 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread* current))
291 JRT_BLOCK;
292 #ifndef PRODUCT
293 SharedRuntime::_new_array_ctr++; // new array requires GC
294 #endif
295 assert(check_compiled_frame(current), "incorrect caller");
296
297 // Scavenge and allocate an instance.
298 oop result;
299
300 assert(array_type->is_typeArray_klass(), "should be called only for type array");
301 // The oopFactory likes to work with the element type.
302 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
303 result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD);
304
305 // Pass oops back through thread local storage. Our apparent type to Java
306 // is that we return an oop, but we can block on exit from this routine and
307 // a GC can trash the oop in C's return register. The generated stub will
308 // fetch the oop from TLS after any possible GC.
309 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
310 current->set_vm_result(result);
311 JRT_BLOCK_END;
312
313
314 // inform GC that we won't do card marks for initializing writes.
315 SharedRuntime::on_slowpath_allocation_exit(current);
316
317 oop result = current->vm_result();
318 if ((len > 0) && (result != nullptr) &&
319 is_deoptimized_caller_frame(current)) {
320 // Zero array here if the caller is deoptimized.
321 const size_t size = TypeArrayKlass::cast(array_type)->oop_size(result);
322 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
323 const size_t hs = arrayOopDesc::header_size(elem_type);
324 // Align to next 8 bytes to avoid trashing arrays's length.
325 const size_t aligned_hs = align_object_offset(hs);
326 HeapWord* obj = cast_from_oop<HeapWord*>(result);
327 if (aligned_hs > hs) {
328 Copy::zero_to_words(obj+hs, aligned_hs-hs);
329 }
330 // Optimized zeroing.
331 Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs);
332 }
333
334 JRT_END
335
336 // Note: multianewarray for one dimension is handled inline by GraphKit::new_array.
337
338 // multianewarray for 2 dimensions
339 JRT_ENTRY(void, OptoRuntime::multianewarray2_C(Klass* elem_type, int len1, int len2, JavaThread* current))
340 #ifndef PRODUCT
341 SharedRuntime::_multi2_ctr++; // multianewarray for 1 dimension
342 #endif
343 assert(check_compiled_frame(current), "incorrect caller");
344 assert(elem_type->is_klass(), "not a class");
345 jint dims[2];
346 dims[0] = len1;
347 dims[1] = len2;
348 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
349 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD);
350 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
351 current->set_vm_result(obj);
352 JRT_END
353
354 // multianewarray for 3 dimensions
355 JRT_ENTRY(void, OptoRuntime::multianewarray3_C(Klass* elem_type, int len1, int len2, int len3, JavaThread* current))
356 #ifndef PRODUCT
357 SharedRuntime::_multi3_ctr++; // multianewarray for 1 dimension
358 #endif
359 assert(check_compiled_frame(current), "incorrect caller");
360 assert(elem_type->is_klass(), "not a class");
361 jint dims[3];
362 dims[0] = len1;
363 dims[1] = len2;
364 dims[2] = len3;
365 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
366 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD);
367 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
368 current->set_vm_result(obj);
369 JRT_END
370
371 // multianewarray for 4 dimensions
372 JRT_ENTRY(void, OptoRuntime::multianewarray4_C(Klass* elem_type, int len1, int len2, int len3, int len4, JavaThread* current))
373 #ifndef PRODUCT
374 SharedRuntime::_multi4_ctr++; // multianewarray for 1 dimension
375 #endif
376 assert(check_compiled_frame(current), "incorrect caller");
377 assert(elem_type->is_klass(), "not a class");
378 jint dims[4];
379 dims[0] = len1;
380 dims[1] = len2;
381 dims[2] = len3;
382 dims[3] = len4;
383 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
384 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD);
385 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
386 current->set_vm_result(obj);
387 JRT_END
388
389 // multianewarray for 5 dimensions
390 JRT_ENTRY(void, OptoRuntime::multianewarray5_C(Klass* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread* current))
391 #ifndef PRODUCT
392 SharedRuntime::_multi5_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[5];
397 dims[0] = len1;
398 dims[1] = len2;
399 dims[2] = len3;
400 dims[3] = len4;
401 dims[4] = len5;
402 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
403 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD);
404 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
405 current->set_vm_result(obj);
406 JRT_END
407
408 JRT_ENTRY(void, OptoRuntime::multianewarrayN_C(Klass* elem_type, arrayOopDesc* dims, JavaThread* current))
409 assert(check_compiled_frame(current), "incorrect caller");
410 assert(elem_type->is_klass(), "not a class");
411 assert(oop(dims)->is_typeArray(), "not an array");
412
413 ResourceMark rm;
414 jint len = dims->length();
415 assert(len > 0, "Dimensions array should contain data");
416 jint *c_dims = NEW_RESOURCE_ARRAY(jint, len);
417 ArrayAccess<>::arraycopy_to_native<>(dims, typeArrayOopDesc::element_offset<jint>(0),
418 c_dims, len);
419
420 Handle holder(current, elem_type->klass_holder()); // keep the klass alive
421 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(len, c_dims, THREAD);
422 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
423 current->set_vm_result(obj);
424 JRT_END
425
426 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notify_C(oopDesc* obj, JavaThread* current))
427
428 // Very few notify/notifyAll operations find any threads on the waitset, so
429 // the dominant fast-path is to simply return.
430 // Relatedly, it's critical that notify/notifyAll be fast in order to
431 // reduce lock hold times.
432 if (!SafepointSynchronize::is_synchronizing()) {
433 if (ObjectSynchronizer::quick_notify(obj, current, false)) {
434 return;
435 }
436 }
437
438 // This is the case the fast-path above isn't provisioned to handle.
439 // The fast-path is designed to handle frequently arising cases in an efficient manner.
440 // (The fast-path is just a degenerate variant of the slow-path).
441 // Perform the dreaded state transition and pass control into the slow-path.
442 JRT_BLOCK;
443 Handle h_obj(current, obj);
444 ObjectSynchronizer::notify(h_obj, CHECK);
445 JRT_BLOCK_END;
446 JRT_END
447
448 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notifyAll_C(oopDesc* obj, JavaThread* current))
449
450 if (!SafepointSynchronize::is_synchronizing() ) {
451 if (ObjectSynchronizer::quick_notify(obj, current, true)) {
452 return;
453 }
454 }
455
456 // This is the case the fast-path above isn't provisioned to handle.
457 // The fast-path is designed to handle frequently arising cases in an efficient manner.
458 // (The fast-path is just a degenerate variant of the slow-path).
459 // Perform the dreaded state transition and pass control into the slow-path.
460 JRT_BLOCK;
461 Handle h_obj(current, obj);
462 ObjectSynchronizer::notifyall(h_obj, CHECK);
463 JRT_BLOCK_END;
464 JRT_END
465
466 const TypeFunc *OptoRuntime::new_instance_Type() {
467 // create input type (domain)
468 const Type **fields = TypeTuple::fields(1);
469 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
470 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
471
472 // create result type (range)
473 fields = TypeTuple::fields(1);
474 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
475
476 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
477
478 return TypeFunc::make(domain, range);
479 }
480
481 #if INCLUDE_JVMTI
482 const TypeFunc *OptoRuntime::notify_jvmti_vthread_Type() {
483 // create input type (domain)
484 const Type **fields = TypeTuple::fields(2);
485 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // VirtualThread oop
486 fields[TypeFunc::Parms+1] = TypeInt::BOOL; // jboolean
487 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
488
489 // no result type needed
490 fields = TypeTuple::fields(1);
491 fields[TypeFunc::Parms+0] = nullptr; // void
492 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
493
494 return TypeFunc::make(domain,range);
495 }
496 #endif
497
498 const TypeFunc *OptoRuntime::athrow_Type() {
499 // create input type (domain)
500 const Type **fields = TypeTuple::fields(1);
501 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
502 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
503
504 // create result type (range)
505 fields = TypeTuple::fields(0);
506
507 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
508
509 return TypeFunc::make(domain, range);
510 }
511
512
513 const TypeFunc *OptoRuntime::new_array_Type() {
514 // create input type (domain)
515 const Type **fields = TypeTuple::fields(2);
516 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
517 fields[TypeFunc::Parms+1] = TypeInt::INT; // array size
518 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
519
520 // create result type (range)
521 fields = TypeTuple::fields(1);
522 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
523
524 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
525
526 return TypeFunc::make(domain, range);
527 }
528
529 const TypeFunc *OptoRuntime::multianewarray_Type(int ndim) {
530 // create input type (domain)
531 const int nargs = ndim + 1;
532 const Type **fields = TypeTuple::fields(nargs);
533 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
534 for( int i = 1; i < nargs; i++ )
535 fields[TypeFunc::Parms + i] = TypeInt::INT; // array size
536 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+nargs, fields);
537
538 // create result type (range)
539 fields = TypeTuple::fields(1);
540 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
541 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
542
543 return TypeFunc::make(domain, range);
544 }
545
546 const TypeFunc *OptoRuntime::multianewarray2_Type() {
547 return multianewarray_Type(2);
548 }
549
550 const TypeFunc *OptoRuntime::multianewarray3_Type() {
551 return multianewarray_Type(3);
552 }
553
554 const TypeFunc *OptoRuntime::multianewarray4_Type() {
555 return multianewarray_Type(4);
556 }
557
558 const TypeFunc *OptoRuntime::multianewarray5_Type() {
559 return multianewarray_Type(5);
560 }
561
562 const TypeFunc *OptoRuntime::multianewarrayN_Type() {
563 // create input type (domain)
564 const Type **fields = TypeTuple::fields(2);
565 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass
566 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // array of dim sizes
567 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
568
569 // create result type (range)
570 fields = TypeTuple::fields(1);
571 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
572 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
573
574 return TypeFunc::make(domain, range);
575 }
576
577 const TypeFunc *OptoRuntime::uncommon_trap_Type() {
578 // create input type (domain)
579 const Type **fields = TypeTuple::fields(1);
580 fields[TypeFunc::Parms+0] = TypeInt::INT; // trap_reason (deopt reason and action)
581 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
582
583 // create result type (range)
584 fields = TypeTuple::fields(0);
585 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
586
587 return TypeFunc::make(domain, range);
588 }
589
590 //-----------------------------------------------------------------------------
591 // Monitor Handling
592 const TypeFunc *OptoRuntime::complete_monitor_enter_Type() {
593 // create input type (domain)
594 const Type **fields = TypeTuple::fields(2);
595 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
596 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock
597 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
598
599 // create result type (range)
600 fields = TypeTuple::fields(0);
601
602 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
603
604 return TypeFunc::make(domain,range);
605 }
606
607
608 //-----------------------------------------------------------------------------
609 const TypeFunc *OptoRuntime::complete_monitor_exit_Type() {
610 // create input type (domain)
611 const Type **fields = TypeTuple::fields(3);
612 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
613 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock - BasicLock
614 fields[TypeFunc::Parms+2] = TypeRawPtr::BOTTOM; // Thread pointer (Self)
615 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields);
616
617 // create result type (range)
618 fields = TypeTuple::fields(0);
619
620 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
621
622 return TypeFunc::make(domain, range);
623 }
624
625 const TypeFunc *OptoRuntime::monitor_notify_Type() {
626 // create input type (domain)
627 const Type **fields = TypeTuple::fields(1);
628 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked
629 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
630
631 // create result type (range)
632 fields = TypeTuple::fields(0);
633 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
634 return TypeFunc::make(domain, range);
635 }
636
637 const TypeFunc* OptoRuntime::flush_windows_Type() {
638 // create input type (domain)
639 const Type** fields = TypeTuple::fields(1);
640 fields[TypeFunc::Parms+0] = nullptr; // void
641 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields);
642
643 // create result type
644 fields = TypeTuple::fields(1);
645 fields[TypeFunc::Parms+0] = nullptr; // void
646 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
647
648 return TypeFunc::make(domain, range);
649 }
650
651 const TypeFunc* OptoRuntime::l2f_Type() {
652 // create input type (domain)
653 const Type **fields = TypeTuple::fields(2);
654 fields[TypeFunc::Parms+0] = TypeLong::LONG;
655 fields[TypeFunc::Parms+1] = Type::HALF;
656 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
657
658 // create result type (range)
659 fields = TypeTuple::fields(1);
660 fields[TypeFunc::Parms+0] = Type::FLOAT;
661 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
662
663 return TypeFunc::make(domain, range);
664 }
665
666 const TypeFunc* OptoRuntime::modf_Type() {
667 const Type **fields = TypeTuple::fields(2);
668 fields[TypeFunc::Parms+0] = Type::FLOAT;
669 fields[TypeFunc::Parms+1] = Type::FLOAT;
670 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
671
672 // create result type (range)
673 fields = TypeTuple::fields(1);
674 fields[TypeFunc::Parms+0] = Type::FLOAT;
675
676 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
677
678 return TypeFunc::make(domain, range);
679 }
680
681 const TypeFunc *OptoRuntime::Math_D_D_Type() {
682 // create input type (domain)
683 const Type **fields = TypeTuple::fields(2);
684 // Symbol* name of class to be loaded
685 fields[TypeFunc::Parms+0] = Type::DOUBLE;
686 fields[TypeFunc::Parms+1] = Type::HALF;
687 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
688
689 // create result type (range)
690 fields = TypeTuple::fields(2);
691 fields[TypeFunc::Parms+0] = Type::DOUBLE;
692 fields[TypeFunc::Parms+1] = Type::HALF;
693 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
694
695 return TypeFunc::make(domain, range);
696 }
697
698 const TypeFunc *OptoRuntime::Math_Vector_Vector_Type(uint num_arg, const TypeVect* in_type, const TypeVect* out_type) {
699 // create input type (domain)
700 const Type **fields = TypeTuple::fields(num_arg);
701 // Symbol* name of class to be loaded
702 assert(num_arg > 0, "must have at least 1 input");
703 for (uint i = 0; i < num_arg; i++) {
704 fields[TypeFunc::Parms+i] = in_type;
705 }
706 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+num_arg, fields);
707
708 // create result type (range)
709 const uint num_ret = 1;
710 fields = TypeTuple::fields(num_ret);
711 fields[TypeFunc::Parms+0] = out_type;
712 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+num_ret, fields);
713
714 return TypeFunc::make(domain, range);
715 }
716
717 const TypeFunc* OptoRuntime::Math_DD_D_Type() {
718 const Type **fields = TypeTuple::fields(4);
719 fields[TypeFunc::Parms+0] = Type::DOUBLE;
720 fields[TypeFunc::Parms+1] = Type::HALF;
721 fields[TypeFunc::Parms+2] = Type::DOUBLE;
722 fields[TypeFunc::Parms+3] = Type::HALF;
723 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+4, fields);
724
725 // create result type (range)
726 fields = TypeTuple::fields(2);
727 fields[TypeFunc::Parms+0] = Type::DOUBLE;
728 fields[TypeFunc::Parms+1] = Type::HALF;
729 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
730
731 return TypeFunc::make(domain, range);
732 }
733
734 //-------------- currentTimeMillis, currentTimeNanos, etc
735
736 const TypeFunc* OptoRuntime::void_long_Type() {
737 // create input type (domain)
738 const Type **fields = TypeTuple::fields(0);
739 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+0, fields);
740
741 // create result type (range)
742 fields = TypeTuple::fields(2);
743 fields[TypeFunc::Parms+0] = TypeLong::LONG;
744 fields[TypeFunc::Parms+1] = Type::HALF;
745 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
746
747 return TypeFunc::make(domain, range);
748 }
749
750 const TypeFunc* OptoRuntime::void_void_Type() {
751 // create input type (domain)
752 const Type **fields = TypeTuple::fields(0);
753 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+0, fields);
754
755 // create result type (range)
756 fields = TypeTuple::fields(0);
757 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
758 return TypeFunc::make(domain, range);
759 }
760
761 const TypeFunc* OptoRuntime::jfr_write_checkpoint_Type() {
762 // create input type (domain)
763 const Type **fields = TypeTuple::fields(0);
764 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields);
765
766 // create result type (range)
767 fields = TypeTuple::fields(0);
768 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
769 return TypeFunc::make(domain, range);
770 }
771
772
773 // arraycopy stub variations:
774 enum ArrayCopyType {
775 ac_fast, // void(ptr, ptr, size_t)
776 ac_checkcast, // int(ptr, ptr, size_t, size_t, ptr)
777 ac_slow, // void(ptr, int, ptr, int, int)
778 ac_generic // int(ptr, int, ptr, int, int)
779 };
780
781 static const TypeFunc* make_arraycopy_Type(ArrayCopyType act) {
782 // create input type (domain)
783 int num_args = (act == ac_fast ? 3 : 5);
784 int num_size_args = (act == ac_fast ? 1 : act == ac_checkcast ? 2 : 0);
785 int argcnt = num_args;
786 LP64_ONLY(argcnt += num_size_args); // halfwords for lengths
787 const Type** fields = TypeTuple::fields(argcnt);
788 int argp = TypeFunc::Parms;
789 fields[argp++] = TypePtr::NOTNULL; // src
790 if (num_size_args == 0) {
791 fields[argp++] = TypeInt::INT; // src_pos
792 }
793 fields[argp++] = TypePtr::NOTNULL; // dest
794 if (num_size_args == 0) {
795 fields[argp++] = TypeInt::INT; // dest_pos
796 fields[argp++] = TypeInt::INT; // length
797 }
798 while (num_size_args-- > 0) {
799 fields[argp++] = TypeX_X; // size in whatevers (size_t)
800 LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length
801 }
802 if (act == ac_checkcast) {
803 fields[argp++] = TypePtr::NOTNULL; // super_klass
804 }
805 assert(argp == TypeFunc::Parms+argcnt, "correct decoding of act");
806 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
807
808 // create result type if needed
809 int retcnt = (act == ac_checkcast || act == ac_generic ? 1 : 0);
810 fields = TypeTuple::fields(1);
811 if (retcnt == 0)
812 fields[TypeFunc::Parms+0] = nullptr; // void
813 else
814 fields[TypeFunc::Parms+0] = TypeInt::INT; // status result, if needed
815 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+retcnt, fields);
816 return TypeFunc::make(domain, range);
817 }
818
819 const TypeFunc* OptoRuntime::fast_arraycopy_Type() {
820 // This signature is simple: Two base pointers and a size_t.
821 return make_arraycopy_Type(ac_fast);
822 }
823
824 const TypeFunc* OptoRuntime::checkcast_arraycopy_Type() {
825 // An extension of fast_arraycopy_Type which adds type checking.
826 return make_arraycopy_Type(ac_checkcast);
827 }
828
829 const TypeFunc* OptoRuntime::slow_arraycopy_Type() {
830 // This signature is exactly the same as System.arraycopy.
831 // There are no intptr_t (int/long) arguments.
832 return make_arraycopy_Type(ac_slow);
833 }
834
835 const TypeFunc* OptoRuntime::generic_arraycopy_Type() {
836 // This signature is like System.arraycopy, except that it returns status.
837 return make_arraycopy_Type(ac_generic);
838 }
839
840
841 const TypeFunc* OptoRuntime::array_fill_Type() {
842 const Type** fields;
843 int argp = TypeFunc::Parms;
844 // create input type (domain): pointer, int, size_t
845 fields = TypeTuple::fields(3 LP64_ONLY( + 1));
846 fields[argp++] = TypePtr::NOTNULL;
847 fields[argp++] = TypeInt::INT;
848 fields[argp++] = TypeX_X; // size in whatevers (size_t)
849 LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length
850 const TypeTuple *domain = TypeTuple::make(argp, fields);
851
852 // create result type
853 fields = TypeTuple::fields(1);
854 fields[TypeFunc::Parms+0] = nullptr; // void
855 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
856
857 return TypeFunc::make(domain, range);
858 }
859
860 // for aescrypt encrypt/decrypt operations, just three pointers returning void (length is constant)
861 const TypeFunc* OptoRuntime::aescrypt_block_Type() {
862 // create input type (domain)
863 int num_args = 3;
864 int argcnt = num_args;
865 const Type** fields = TypeTuple::fields(argcnt);
866 int argp = TypeFunc::Parms;
867 fields[argp++] = TypePtr::NOTNULL; // src
868 fields[argp++] = TypePtr::NOTNULL; // dest
869 fields[argp++] = TypePtr::NOTNULL; // k array
870 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
871 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
872
873 // no result type needed
874 fields = TypeTuple::fields(1);
875 fields[TypeFunc::Parms+0] = nullptr; // void
876 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
877 return TypeFunc::make(domain, range);
878 }
879
880 /**
881 * int updateBytesCRC32(int crc, byte* b, int len)
882 */
883 const TypeFunc* OptoRuntime::updateBytesCRC32_Type() {
884 // create input type (domain)
885 int num_args = 3;
886 int argcnt = num_args;
887 const Type** fields = TypeTuple::fields(argcnt);
888 int argp = TypeFunc::Parms;
889 fields[argp++] = TypeInt::INT; // crc
890 fields[argp++] = TypePtr::NOTNULL; // src
891 fields[argp++] = TypeInt::INT; // len
892 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
893 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
894
895 // result type needed
896 fields = TypeTuple::fields(1);
897 fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result
898 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
899 return TypeFunc::make(domain, range);
900 }
901
902 /**
903 * int updateBytesCRC32C(int crc, byte* buf, int len, int* table)
904 */
905 const TypeFunc* OptoRuntime::updateBytesCRC32C_Type() {
906 // create input type (domain)
907 int num_args = 4;
908 int argcnt = num_args;
909 const Type** fields = TypeTuple::fields(argcnt);
910 int argp = TypeFunc::Parms;
911 fields[argp++] = TypeInt::INT; // crc
912 fields[argp++] = TypePtr::NOTNULL; // buf
913 fields[argp++] = TypeInt::INT; // len
914 fields[argp++] = TypePtr::NOTNULL; // table
915 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
916 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
917
918 // result type needed
919 fields = TypeTuple::fields(1);
920 fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result
921 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
922 return TypeFunc::make(domain, range);
923 }
924
925 /**
926 * int updateBytesAdler32(int adler, bytes* b, int off, int len)
927 */
928 const TypeFunc* OptoRuntime::updateBytesAdler32_Type() {
929 // create input type (domain)
930 int num_args = 3;
931 int argcnt = num_args;
932 const Type** fields = TypeTuple::fields(argcnt);
933 int argp = TypeFunc::Parms;
934 fields[argp++] = TypeInt::INT; // crc
935 fields[argp++] = TypePtr::NOTNULL; // src + offset
936 fields[argp++] = TypeInt::INT; // len
937 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
938 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
939
940 // result type needed
941 fields = TypeTuple::fields(1);
942 fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result
943 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
944 return TypeFunc::make(domain, range);
945 }
946
947 // for cipherBlockChaining calls of aescrypt encrypt/decrypt, four pointers and a length, returning int
948 const TypeFunc* OptoRuntime::cipherBlockChaining_aescrypt_Type() {
949 // create input type (domain)
950 int num_args = 5;
951 int argcnt = num_args;
952 const Type** fields = TypeTuple::fields(argcnt);
953 int argp = TypeFunc::Parms;
954 fields[argp++] = TypePtr::NOTNULL; // src
955 fields[argp++] = TypePtr::NOTNULL; // dest
956 fields[argp++] = TypePtr::NOTNULL; // k array
957 fields[argp++] = TypePtr::NOTNULL; // r array
958 fields[argp++] = TypeInt::INT; // src len
959 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
960 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
961
962 // returning cipher len (int)
963 fields = TypeTuple::fields(1);
964 fields[TypeFunc::Parms+0] = TypeInt::INT;
965 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
966 return TypeFunc::make(domain, range);
967 }
968
969 // for electronicCodeBook calls of aescrypt encrypt/decrypt, three pointers and a length, returning int
970 const TypeFunc* OptoRuntime::electronicCodeBook_aescrypt_Type() {
971 // create input type (domain)
972 int num_args = 4;
973 int argcnt = num_args;
974 const Type** fields = TypeTuple::fields(argcnt);
975 int argp = TypeFunc::Parms;
976 fields[argp++] = TypePtr::NOTNULL; // src
977 fields[argp++] = TypePtr::NOTNULL; // dest
978 fields[argp++] = TypePtr::NOTNULL; // k array
979 fields[argp++] = TypeInt::INT; // src len
980 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
981 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
982
983 // returning cipher len (int)
984 fields = TypeTuple::fields(1);
985 fields[TypeFunc::Parms + 0] = TypeInt::INT;
986 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
987 return TypeFunc::make(domain, range);
988 }
989
990 //for counterMode calls of aescrypt encrypt/decrypt, four pointers and a length, returning int
991 const TypeFunc* OptoRuntime::counterMode_aescrypt_Type() {
992 // create input type (domain)
993 int num_args = 7;
994 int argcnt = num_args;
995 const Type** fields = TypeTuple::fields(argcnt);
996 int argp = TypeFunc::Parms;
997 fields[argp++] = TypePtr::NOTNULL; // src
998 fields[argp++] = TypePtr::NOTNULL; // dest
999 fields[argp++] = TypePtr::NOTNULL; // k array
1000 fields[argp++] = TypePtr::NOTNULL; // counter array
1001 fields[argp++] = TypeInt::INT; // src len
1002 fields[argp++] = TypePtr::NOTNULL; // saved_encCounter
1003 fields[argp++] = TypePtr::NOTNULL; // saved used addr
1004 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1005 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1006 // returning cipher len (int)
1007 fields = TypeTuple::fields(1);
1008 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1009 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1010 return TypeFunc::make(domain, range);
1011 }
1012
1013 //for counterMode calls of aescrypt encrypt/decrypt, four pointers and a length, returning int
1014 const TypeFunc* OptoRuntime::galoisCounterMode_aescrypt_Type() {
1015 // create input type (domain)
1016 int num_args = 8;
1017 int argcnt = num_args;
1018 const Type** fields = TypeTuple::fields(argcnt);
1019 int argp = TypeFunc::Parms;
1020 fields[argp++] = TypePtr::NOTNULL; // byte[] in + inOfs
1021 fields[argp++] = TypeInt::INT; // int len
1022 fields[argp++] = TypePtr::NOTNULL; // byte[] ct + ctOfs
1023 fields[argp++] = TypePtr::NOTNULL; // byte[] out + outOfs
1024 fields[argp++] = TypePtr::NOTNULL; // byte[] key from AESCrypt obj
1025 fields[argp++] = TypePtr::NOTNULL; // long[] state from GHASH obj
1026 fields[argp++] = TypePtr::NOTNULL; // long[] subkeyHtbl from GHASH obj
1027 fields[argp++] = TypePtr::NOTNULL; // byte[] counter from GCTR obj
1028
1029 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1030 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1031 // returning cipher len (int)
1032 fields = TypeTuple::fields(1);
1033 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1034 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1035 return TypeFunc::make(domain, range);
1036 }
1037
1038 /*
1039 * void implCompress(byte[] buf, int ofs)
1040 */
1041 const TypeFunc* OptoRuntime::digestBase_implCompress_Type(bool is_sha3) {
1042 // create input type (domain)
1043 int num_args = is_sha3 ? 3 : 2;
1044 int argcnt = num_args;
1045 const Type** fields = TypeTuple::fields(argcnt);
1046 int argp = TypeFunc::Parms;
1047 fields[argp++] = TypePtr::NOTNULL; // buf
1048 fields[argp++] = TypePtr::NOTNULL; // state
1049 if (is_sha3) fields[argp++] = TypeInt::INT; // block_size
1050 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1051 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1052
1053 // no result type needed
1054 fields = TypeTuple::fields(1);
1055 fields[TypeFunc::Parms+0] = nullptr; // void
1056 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1057 return TypeFunc::make(domain, range);
1058 }
1059
1060 /*
1061 * int implCompressMultiBlock(byte[] b, int ofs, int limit)
1062 */
1063 const TypeFunc* OptoRuntime::digestBase_implCompressMB_Type(bool is_sha3) {
1064 // create input type (domain)
1065 int num_args = is_sha3 ? 5 : 4;
1066 int argcnt = num_args;
1067 const Type** fields = TypeTuple::fields(argcnt);
1068 int argp = TypeFunc::Parms;
1069 fields[argp++] = TypePtr::NOTNULL; // buf
1070 fields[argp++] = TypePtr::NOTNULL; // state
1071 if (is_sha3) fields[argp++] = TypeInt::INT; // block_size
1072 fields[argp++] = TypeInt::INT; // ofs
1073 fields[argp++] = TypeInt::INT; // limit
1074 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1075 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1076
1077 // returning ofs (int)
1078 fields = TypeTuple::fields(1);
1079 fields[TypeFunc::Parms+0] = TypeInt::INT; // ofs
1080 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
1081 return TypeFunc::make(domain, range);
1082 }
1083
1084 const TypeFunc* OptoRuntime::multiplyToLen_Type() {
1085 // create input type (domain)
1086 int num_args = 6;
1087 int argcnt = num_args;
1088 const Type** fields = TypeTuple::fields(argcnt);
1089 int argp = TypeFunc::Parms;
1090 fields[argp++] = TypePtr::NOTNULL; // x
1091 fields[argp++] = TypeInt::INT; // xlen
1092 fields[argp++] = TypePtr::NOTNULL; // y
1093 fields[argp++] = TypeInt::INT; // ylen
1094 fields[argp++] = TypePtr::NOTNULL; // z
1095 fields[argp++] = TypeInt::INT; // zlen
1096 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1097 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1098
1099 // no result type needed
1100 fields = TypeTuple::fields(1);
1101 fields[TypeFunc::Parms+0] = nullptr;
1102 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1103 return TypeFunc::make(domain, range);
1104 }
1105
1106 const TypeFunc* OptoRuntime::squareToLen_Type() {
1107 // create input type (domain)
1108 int num_args = 4;
1109 int argcnt = num_args;
1110 const Type** fields = TypeTuple::fields(argcnt);
1111 int argp = TypeFunc::Parms;
1112 fields[argp++] = TypePtr::NOTNULL; // x
1113 fields[argp++] = TypeInt::INT; // len
1114 fields[argp++] = TypePtr::NOTNULL; // z
1115 fields[argp++] = TypeInt::INT; // zlen
1116 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1117 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1118
1119 // no result type needed
1120 fields = TypeTuple::fields(1);
1121 fields[TypeFunc::Parms+0] = nullptr;
1122 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1123 return TypeFunc::make(domain, range);
1124 }
1125
1126 // for mulAdd calls, 2 pointers and 3 ints, returning int
1127 const TypeFunc* OptoRuntime::mulAdd_Type() {
1128 // create input type (domain)
1129 int num_args = 5;
1130 int argcnt = num_args;
1131 const Type** fields = TypeTuple::fields(argcnt);
1132 int argp = TypeFunc::Parms;
1133 fields[argp++] = TypePtr::NOTNULL; // out
1134 fields[argp++] = TypePtr::NOTNULL; // in
1135 fields[argp++] = TypeInt::INT; // offset
1136 fields[argp++] = TypeInt::INT; // len
1137 fields[argp++] = TypeInt::INT; // k
1138 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1139 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1140
1141 // returning carry (int)
1142 fields = TypeTuple::fields(1);
1143 fields[TypeFunc::Parms+0] = TypeInt::INT;
1144 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
1145 return TypeFunc::make(domain, range);
1146 }
1147
1148 const TypeFunc* OptoRuntime::montgomeryMultiply_Type() {
1149 // create input type (domain)
1150 int num_args = 7;
1151 int argcnt = num_args;
1152 const Type** fields = TypeTuple::fields(argcnt);
1153 int argp = TypeFunc::Parms;
1154 fields[argp++] = TypePtr::NOTNULL; // a
1155 fields[argp++] = TypePtr::NOTNULL; // b
1156 fields[argp++] = TypePtr::NOTNULL; // n
1157 fields[argp++] = TypeInt::INT; // len
1158 fields[argp++] = TypeLong::LONG; // inv
1159 fields[argp++] = Type::HALF;
1160 fields[argp++] = TypePtr::NOTNULL; // result
1161 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1162 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1163
1164 // result type needed
1165 fields = TypeTuple::fields(1);
1166 fields[TypeFunc::Parms+0] = TypePtr::NOTNULL;
1167
1168 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1169 return TypeFunc::make(domain, range);
1170 }
1171
1172 const TypeFunc* OptoRuntime::montgomerySquare_Type() {
1173 // create input type (domain)
1174 int num_args = 6;
1175 int argcnt = num_args;
1176 const Type** fields = TypeTuple::fields(argcnt);
1177 int argp = TypeFunc::Parms;
1178 fields[argp++] = TypePtr::NOTNULL; // a
1179 fields[argp++] = TypePtr::NOTNULL; // n
1180 fields[argp++] = TypeInt::INT; // len
1181 fields[argp++] = TypeLong::LONG; // inv
1182 fields[argp++] = Type::HALF;
1183 fields[argp++] = TypePtr::NOTNULL; // result
1184 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1185 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1186
1187 // result type needed
1188 fields = TypeTuple::fields(1);
1189 fields[TypeFunc::Parms+0] = TypePtr::NOTNULL;
1190
1191 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1192 return TypeFunc::make(domain, range);
1193 }
1194
1195 const TypeFunc * OptoRuntime::bigIntegerShift_Type() {
1196 int argcnt = 5;
1197 const Type** fields = TypeTuple::fields(argcnt);
1198 int argp = TypeFunc::Parms;
1199 fields[argp++] = TypePtr::NOTNULL; // newArr
1200 fields[argp++] = TypePtr::NOTNULL; // oldArr
1201 fields[argp++] = TypeInt::INT; // newIdx
1202 fields[argp++] = TypeInt::INT; // shiftCount
1203 fields[argp++] = TypeInt::INT; // numIter
1204 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1205 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1206
1207 // no result type needed
1208 fields = TypeTuple::fields(1);
1209 fields[TypeFunc::Parms + 0] = nullptr;
1210 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1211 return TypeFunc::make(domain, range);
1212 }
1213
1214 const TypeFunc* OptoRuntime::vectorizedMismatch_Type() {
1215 // create input type (domain)
1216 int num_args = 4;
1217 int argcnt = num_args;
1218 const Type** fields = TypeTuple::fields(argcnt);
1219 int argp = TypeFunc::Parms;
1220 fields[argp++] = TypePtr::NOTNULL; // obja
1221 fields[argp++] = TypePtr::NOTNULL; // objb
1222 fields[argp++] = TypeInt::INT; // length, number of elements
1223 fields[argp++] = TypeInt::INT; // log2scale, element size
1224 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1225 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1226
1227 //return mismatch index (int)
1228 fields = TypeTuple::fields(1);
1229 fields[TypeFunc::Parms + 0] = TypeInt::INT;
1230 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1231 return TypeFunc::make(domain, range);
1232 }
1233
1234 // GHASH block processing
1235 const TypeFunc* OptoRuntime::ghash_processBlocks_Type() {
1236 int argcnt = 4;
1237
1238 const Type** fields = TypeTuple::fields(argcnt);
1239 int argp = TypeFunc::Parms;
1240 fields[argp++] = TypePtr::NOTNULL; // state
1241 fields[argp++] = TypePtr::NOTNULL; // subkeyH
1242 fields[argp++] = TypePtr::NOTNULL; // data
1243 fields[argp++] = TypeInt::INT; // blocks
1244 assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1245 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1246
1247 // result type needed
1248 fields = TypeTuple::fields(1);
1249 fields[TypeFunc::Parms+0] = nullptr; // void
1250 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1251 return TypeFunc::make(domain, range);
1252 }
1253
1254 // ChaCha20 Block function
1255 const TypeFunc* OptoRuntime::chacha20Block_Type() {
1256 int argcnt = 2;
1257
1258 const Type** fields = TypeTuple::fields(argcnt);
1259 int argp = TypeFunc::Parms;
1260 fields[argp++] = TypePtr::NOTNULL; // state
1261 fields[argp++] = TypePtr::NOTNULL; // result
1262
1263 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1264 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1265
1266 // result type needed
1267 fields = TypeTuple::fields(1);
1268 fields[TypeFunc::Parms + 0] = TypeInt::INT; // key stream outlen as int
1269 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1270 return TypeFunc::make(domain, range);
1271 }
1272
1273 // Base64 encode function
1274 const TypeFunc* OptoRuntime::base64_encodeBlock_Type() {
1275 int argcnt = 6;
1276
1277 const Type** fields = TypeTuple::fields(argcnt);
1278 int argp = TypeFunc::Parms;
1279 fields[argp++] = TypePtr::NOTNULL; // src array
1280 fields[argp++] = TypeInt::INT; // offset
1281 fields[argp++] = TypeInt::INT; // length
1282 fields[argp++] = TypePtr::NOTNULL; // dest array
1283 fields[argp++] = TypeInt::INT; // dp
1284 fields[argp++] = TypeInt::BOOL; // isURL
1285 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1286 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1287
1288 // result type needed
1289 fields = TypeTuple::fields(1);
1290 fields[TypeFunc::Parms + 0] = nullptr; // void
1291 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1292 return TypeFunc::make(domain, range);
1293 }
1294 // Base64 decode function
1295 const TypeFunc* OptoRuntime::base64_decodeBlock_Type() {
1296 int argcnt = 7;
1297
1298 const Type** fields = TypeTuple::fields(argcnt);
1299 int argp = TypeFunc::Parms;
1300 fields[argp++] = TypePtr::NOTNULL; // src array
1301 fields[argp++] = TypeInt::INT; // src offset
1302 fields[argp++] = TypeInt::INT; // src length
1303 fields[argp++] = TypePtr::NOTNULL; // dest array
1304 fields[argp++] = TypeInt::INT; // dest offset
1305 fields[argp++] = TypeInt::BOOL; // isURL
1306 fields[argp++] = TypeInt::BOOL; // isMIME
1307 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1308 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1309
1310 // result type needed
1311 fields = TypeTuple::fields(1);
1312 fields[TypeFunc::Parms + 0] = TypeInt::INT; // count of bytes written to dst
1313 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1314 return TypeFunc::make(domain, range);
1315 }
1316
1317 // Poly1305 processMultipleBlocks function
1318 const TypeFunc* OptoRuntime::poly1305_processBlocks_Type() {
1319 int argcnt = 4;
1320
1321 const Type** fields = TypeTuple::fields(argcnt);
1322 int argp = TypeFunc::Parms;
1323 fields[argp++] = TypePtr::NOTNULL; // input array
1324 fields[argp++] = TypeInt::INT; // input length
1325 fields[argp++] = TypePtr::NOTNULL; // accumulator array
1326 fields[argp++] = TypePtr::NOTNULL; // r array
1327 assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1328 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1329
1330 // result type needed
1331 fields = TypeTuple::fields(1);
1332 fields[TypeFunc::Parms + 0] = nullptr; // void
1333 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1334 return TypeFunc::make(domain, range);
1335 }
1336
1337 //------------- Interpreter state access for on stack replacement
1338 const TypeFunc* OptoRuntime::osr_end_Type() {
1339 // create input type (domain)
1340 const Type **fields = TypeTuple::fields(1);
1341 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // OSR temp buf
1342 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
1343
1344 // create result type
1345 fields = TypeTuple::fields(1);
1346 // fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // locked oop
1347 fields[TypeFunc::Parms+0] = nullptr; // void
1348 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
1349 return TypeFunc::make(domain, range);
1350 }
1351
1352 //-------------------------------------------------------------------------------------
1353 // register policy
1354
1355 bool OptoRuntime::is_callee_saved_register(MachRegisterNumbers reg) {
1356 assert(reg >= 0 && reg < _last_Mach_Reg, "must be a machine register");
1357 switch (register_save_policy[reg]) {
1358 case 'C': return false; //SOC
1359 case 'E': return true ; //SOE
1360 case 'N': return false; //NS
1361 case 'A': return false; //AS
1362 }
1363 ShouldNotReachHere();
1364 return false;
1365 }
1366
1367 //-----------------------------------------------------------------------
1368 // Exceptions
1369 //
1370
1371 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg);
1372
1373 // The method is an entry that is always called by a C++ method not
1374 // directly from compiled code. Compiled code will call the C++ method following.
1375 // We can't allow async exception to be installed during exception processing.
1376 JRT_ENTRY_NO_ASYNC(address, OptoRuntime::handle_exception_C_helper(JavaThread* current, nmethod* &nm))
1377 // The frame we rethrow the exception to might not have been processed by the GC yet.
1378 // The stack watermark barrier takes care of detecting that and ensuring the frame
1379 // has updated oops.
1380 StackWatermarkSet::after_unwind(current);
1381
1382 // Do not confuse exception_oop with pending_exception. The exception_oop
1383 // is only used to pass arguments into the method. Not for general
1384 // exception handling. DO NOT CHANGE IT to use pending_exception, since
1385 // the runtime stubs checks this on exit.
1386 assert(current->exception_oop() != nullptr, "exception oop is found");
1387 address handler_address = nullptr;
1388
1389 Handle exception(current, current->exception_oop());
1390 address pc = current->exception_pc();
1391
1392 // Clear out the exception oop and pc since looking up an
1393 // exception handler can cause class loading, which might throw an
1394 // exception and those fields are expected to be clear during
1395 // normal bytecode execution.
1396 current->clear_exception_oop_and_pc();
1397
1398 LogTarget(Info, exceptions) lt;
1399 if (lt.is_enabled()) {
1400 ResourceMark rm;
1401 LogStream ls(lt);
1402 trace_exception(&ls, exception(), pc, "");
1403 }
1404
1405 // for AbortVMOnException flag
1406 Exceptions::debug_check_abort(exception);
1407
1408 #ifdef ASSERT
1409 if (!(exception->is_a(vmClasses::Throwable_klass()))) {
1410 // should throw an exception here
1411 ShouldNotReachHere();
1412 }
1413 #endif
1414
1415 // new exception handling: this method is entered only from adapters
1416 // exceptions from compiled java methods are handled in compiled code
1417 // using rethrow node
1418
1419 nm = CodeCache::find_nmethod(pc);
1420 assert(nm != nullptr, "No NMethod found");
1421 if (nm->is_native_method()) {
1422 fatal("Native method should not have path to exception handling");
1423 } else {
1424 // we are switching to old paradigm: search for exception handler in caller_frame
1425 // instead in exception handler of caller_frame.sender()
1426
1427 if (JvmtiExport::can_post_on_exceptions()) {
1428 // "Full-speed catching" is not necessary here,
1429 // since we're notifying the VM on every catch.
1430 // Force deoptimization and the rest of the lookup
1431 // will be fine.
1432 deoptimize_caller_frame(current);
1433 }
1434
1435 // Check the stack guard pages. If enabled, look for handler in this frame;
1436 // otherwise, forcibly unwind the frame.
1437 //
1438 // 4826555: use default current sp for reguard_stack instead of &nm: it's more accurate.
1439 bool force_unwind = !current->stack_overflow_state()->reguard_stack();
1440 bool deopting = false;
1441 if (nm->is_deopt_pc(pc)) {
1442 deopting = true;
1443 RegisterMap map(current,
1444 RegisterMap::UpdateMap::skip,
1445 RegisterMap::ProcessFrames::include,
1446 RegisterMap::WalkContinuation::skip);
1447 frame deoptee = current->last_frame().sender(&map);
1448 assert(deoptee.is_deoptimized_frame(), "must be deopted");
1449 // Adjust the pc back to the original throwing pc
1450 pc = deoptee.pc();
1451 }
1452
1453 // If we are forcing an unwind because of stack overflow then deopt is
1454 // irrelevant since we are throwing the frame away anyway.
1455
1456 if (deopting && !force_unwind) {
1457 handler_address = SharedRuntime::deopt_blob()->unpack_with_exception();
1458 } else {
1459
1460 handler_address =
1461 force_unwind ? nullptr : nm->handler_for_exception_and_pc(exception, pc);
1462
1463 if (handler_address == nullptr) {
1464 bool recursive_exception = false;
1465 handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true, recursive_exception);
1466 assert (handler_address != nullptr, "must have compiled handler");
1467 // Update the exception cache only when the unwind was not forced
1468 // and there didn't happen another exception during the computation of the
1469 // compiled exception handler. Checking for exception oop equality is not
1470 // sufficient because some exceptions are pre-allocated and reused.
1471 if (!force_unwind && !recursive_exception) {
1472 nm->add_handler_for_exception_and_pc(exception,pc,handler_address);
1473 }
1474 } else {
1475 #ifdef ASSERT
1476 bool recursive_exception = false;
1477 address computed_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true, recursive_exception);
1478 vmassert(recursive_exception || (handler_address == computed_address), "Handler address inconsistency: " PTR_FORMAT " != " PTR_FORMAT,
1479 p2i(handler_address), p2i(computed_address));
1480 #endif
1481 }
1482 }
1483
1484 current->set_exception_pc(pc);
1485 current->set_exception_handler_pc(handler_address);
1486
1487 // Check if the exception PC is a MethodHandle call site.
1488 current->set_is_method_handle_return(nm->is_method_handle_return(pc));
1489 }
1490
1491 // Restore correct return pc. Was saved above.
1492 current->set_exception_oop(exception());
1493 return handler_address;
1494
1495 JRT_END
1496
1497 // We are entering here from exception_blob
1498 // If there is a compiled exception handler in this method, we will continue there;
1499 // otherwise we will unwind the stack and continue at the caller of top frame method
1500 // Note we enter without the usual JRT wrapper. We will call a helper routine that
1501 // will do the normal VM entry. We do it this way so that we can see if the nmethod
1502 // we looked up the handler for has been deoptimized in the meantime. If it has been
1503 // we must not use the handler and instead return the deopt blob.
1504 address OptoRuntime::handle_exception_C(JavaThread* current) {
1505 //
1506 // We are in Java not VM and in debug mode we have a NoHandleMark
1507 //
1508 #ifndef PRODUCT
1509 SharedRuntime::_find_handler_ctr++; // find exception handler
1510 #endif
1511 debug_only(NoHandleMark __hm;)
1512 nmethod* nm = nullptr;
1513 address handler_address = nullptr;
1514 {
1515 // Enter the VM
1516
1517 ResetNoHandleMark rnhm;
1518 handler_address = handle_exception_C_helper(current, nm);
1519 }
1520
1521 // Back in java: Use no oops, DON'T safepoint
1522
1523 // Now check to see if the handler we are returning is in a now
1524 // deoptimized frame
1525
1526 if (nm != nullptr) {
1527 RegisterMap map(current,
1528 RegisterMap::UpdateMap::skip,
1529 RegisterMap::ProcessFrames::skip,
1530 RegisterMap::WalkContinuation::skip);
1531 frame caller = current->last_frame().sender(&map);
1532 #ifdef ASSERT
1533 assert(caller.is_compiled_frame(), "must be");
1534 #endif // ASSERT
1535 if (caller.is_deoptimized_frame()) {
1536 handler_address = SharedRuntime::deopt_blob()->unpack_with_exception();
1537 }
1538 }
1539 return handler_address;
1540 }
1541
1542 //------------------------------rethrow----------------------------------------
1543 // We get here after compiled code has executed a 'RethrowNode'. The callee
1544 // is either throwing or rethrowing an exception. The callee-save registers
1545 // have been restored, synchronized objects have been unlocked and the callee
1546 // stack frame has been removed. The return address was passed in.
1547 // Exception oop is passed as the 1st argument. This routine is then called
1548 // from the stub. On exit, we know where to jump in the caller's code.
1549 // After this C code exits, the stub will pop his frame and end in a jump
1550 // (instead of a return). We enter the caller's default handler.
1551 //
1552 // This must be JRT_LEAF:
1553 // - caller will not change its state as we cannot block on exit,
1554 // therefore raw_exception_handler_for_return_address is all it takes
1555 // to handle deoptimized blobs
1556 //
1557 // However, there needs to be a safepoint check in the middle! So compiled
1558 // safepoints are completely watertight.
1559 //
1560 // Thus, it cannot be a leaf since it contains the NoSafepointVerifier.
1561 //
1562 // *THIS IS NOT RECOMMENDED PROGRAMMING STYLE*
1563 //
1564 address OptoRuntime::rethrow_C(oopDesc* exception, JavaThread* thread, address ret_pc) {
1565 // ret_pc will have been loaded from the stack, so for AArch64 will be signed.
1566 AARCH64_PORT_ONLY(ret_pc = pauth_strip_verifiable(ret_pc));
1567
1568 #ifndef PRODUCT
1569 SharedRuntime::_rethrow_ctr++; // count rethrows
1570 #endif
1571 assert (exception != nullptr, "should have thrown a NullPointerException");
1572 #ifdef ASSERT
1573 if (!(exception->is_a(vmClasses::Throwable_klass()))) {
1574 // should throw an exception here
1575 ShouldNotReachHere();
1576 }
1577 #endif
1578
1579 thread->set_vm_result(exception);
1580 // Frame not compiled (handles deoptimization blob)
1581 return SharedRuntime::raw_exception_handler_for_return_address(thread, ret_pc);
1582 }
1583
1584
1585 const TypeFunc *OptoRuntime::rethrow_Type() {
1586 // create input type (domain)
1587 const Type **fields = TypeTuple::fields(1);
1588 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop
1589 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
1590
1591 // create result type (range)
1592 fields = TypeTuple::fields(1);
1593 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop
1594 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
1595
1596 return TypeFunc::make(domain, range);
1597 }
1598
1599
1600 void OptoRuntime::deoptimize_caller_frame(JavaThread *thread, bool doit) {
1601 // Deoptimize the caller before continuing, as the compiled
1602 // exception handler table may not be valid.
1603 if (!StressCompiledExceptionHandlers && doit) {
1604 deoptimize_caller_frame(thread);
1605 }
1606 }
1607
1608 void OptoRuntime::deoptimize_caller_frame(JavaThread *thread) {
1609 // Called from within the owner thread, so no need for safepoint
1610 RegisterMap reg_map(thread,
1611 RegisterMap::UpdateMap::include,
1612 RegisterMap::ProcessFrames::include,
1613 RegisterMap::WalkContinuation::skip);
1614 frame stub_frame = thread->last_frame();
1615 assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
1616 frame caller_frame = stub_frame.sender(®_map);
1617
1618 // Deoptimize the caller frame.
1619 Deoptimization::deoptimize_frame(thread, caller_frame.id());
1620 }
1621
1622
1623 bool OptoRuntime::is_deoptimized_caller_frame(JavaThread *thread) {
1624 // Called from within the owner thread, so no need for safepoint
1625 RegisterMap reg_map(thread,
1626 RegisterMap::UpdateMap::include,
1627 RegisterMap::ProcessFrames::include,
1628 RegisterMap::WalkContinuation::skip);
1629 frame stub_frame = thread->last_frame();
1630 assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
1631 frame caller_frame = stub_frame.sender(®_map);
1632 return caller_frame.is_deoptimized_frame();
1633 }
1634
1635
1636 const TypeFunc *OptoRuntime::register_finalizer_Type() {
1637 // create input type (domain)
1638 const Type **fields = TypeTuple::fields(1);
1639 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver
1640 // // The JavaThread* is passed to each routine as the last argument
1641 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
1642 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
1643
1644 // create result type (range)
1645 fields = TypeTuple::fields(0);
1646
1647 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1648
1649 return TypeFunc::make(domain,range);
1650 }
1651
1652 #if INCLUDE_JFR
1653 const TypeFunc *OptoRuntime::class_id_load_barrier_Type() {
1654 // create input type (domain)
1655 const Type **fields = TypeTuple::fields(1);
1656 fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS;
1657 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields);
1658
1659 // create result type (range)
1660 fields = TypeTuple::fields(0);
1661
1662 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields);
1663
1664 return TypeFunc::make(domain,range);
1665 }
1666 #endif
1667
1668 //-----------------------------------------------------------------------------
1669 // Dtrace support. entry and exit probes have the same signature
1670 const TypeFunc *OptoRuntime::dtrace_method_entry_exit_Type() {
1671 // create input type (domain)
1672 const Type **fields = TypeTuple::fields(2);
1673 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1674 fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM; // Method*; Method we are entering
1675 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1676
1677 // create result type (range)
1678 fields = TypeTuple::fields(0);
1679
1680 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1681
1682 return TypeFunc::make(domain,range);
1683 }
1684
1685 const TypeFunc *OptoRuntime::dtrace_object_alloc_Type() {
1686 // create input type (domain)
1687 const Type **fields = TypeTuple::fields(2);
1688 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1689 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object
1690
1691 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1692
1693 // create result type (range)
1694 fields = TypeTuple::fields(0);
1695
1696 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1697
1698 return TypeFunc::make(domain,range);
1699 }
1700
1701
1702 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer(oopDesc* obj, JavaThread* current))
1703 assert(oopDesc::is_oop(obj), "must be a valid oop");
1704 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
1705 InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
1706 JRT_END
1707
1708 //-----------------------------------------------------------------------------
1709
1710 NamedCounter * volatile OptoRuntime::_named_counters = nullptr;
1711
1712 //
1713 // dump the collected NamedCounters.
1714 //
1715 void OptoRuntime::print_named_counters() {
1716 int total_lock_count = 0;
1717 int eliminated_lock_count = 0;
1718
1719 NamedCounter* c = _named_counters;
1720 while (c) {
1721 if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) {
1722 int count = c->count();
1723 if (count > 0) {
1724 bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter;
1725 if (Verbose) {
1726 tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : "");
1727 }
1728 total_lock_count += count;
1729 if (eliminated) {
1730 eliminated_lock_count += count;
1731 }
1732 }
1733 #if INCLUDE_RTM_OPT
1734 } else if (c->tag() == NamedCounter::RTMLockingCounter) {
1735 RTMLockingCounters* rlc = ((RTMLockingNamedCounter*)c)->counters();
1736 if (rlc->nonzero()) {
1737 tty->print_cr("%s", c->name());
1738 rlc->print_on(tty);
1739 }
1740 #endif
1741 }
1742 c = c->next();
1743 }
1744 if (total_lock_count > 0) {
1745 tty->print_cr("dynamic locks: %d", total_lock_count);
1746 if (eliminated_lock_count) {
1747 tty->print_cr("eliminated locks: %d (%d%%)", eliminated_lock_count,
1748 (int)(eliminated_lock_count * 100.0 / total_lock_count));
1749 }
1750 }
1751 }
1752
1753 //
1754 // Allocate a new NamedCounter. The JVMState is used to generate the
1755 // name which consists of method@line for the inlining tree.
1756 //
1757
1758 NamedCounter* OptoRuntime::new_named_counter(JVMState* youngest_jvms, NamedCounter::CounterTag tag) {
1759 int max_depth = youngest_jvms->depth();
1760
1761 // Visit scopes from youngest to oldest.
1762 bool first = true;
1763 stringStream st;
1764 for (int depth = max_depth; depth >= 1; depth--) {
1765 JVMState* jvms = youngest_jvms->of_depth(depth);
1766 ciMethod* m = jvms->has_method() ? jvms->method() : nullptr;
1767 if (!first) {
1768 st.print(" ");
1769 } else {
1770 first = false;
1771 }
1772 int bci = jvms->bci();
1773 if (bci < 0) bci = 0;
1774 if (m != nullptr) {
1775 st.print("%s.%s", m->holder()->name()->as_utf8(), m->name()->as_utf8());
1776 } else {
1777 st.print("no method");
1778 }
1779 st.print("@%d", bci);
1780 // To print linenumbers instead of bci use: m->line_number_from_bci(bci)
1781 }
1782 NamedCounter* c;
1783 if (tag == NamedCounter::RTMLockingCounter) {
1784 c = new RTMLockingNamedCounter(st.freeze());
1785 } else {
1786 c = new NamedCounter(st.freeze(), tag);
1787 }
1788
1789 // atomically add the new counter to the head of the list. We only
1790 // add counters so this is safe.
1791 NamedCounter* head;
1792 do {
1793 c->set_next(nullptr);
1794 head = _named_counters;
1795 c->set_next(head);
1796 } while (Atomic::cmpxchg(&_named_counters, head, c) != head);
1797 return c;
1798 }
1799
1800 int trace_exception_counter = 0;
1801 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
1802 trace_exception_counter++;
1803 stringStream tempst;
1804
1805 tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
1806 exception_oop->print_value_on(&tempst);
1807 tempst.print(" in ");
1808 CodeBlob* blob = CodeCache::find_blob(exception_pc);
1809 if (blob->is_compiled()) {
1810 CompiledMethod* cm = blob->as_compiled_method_or_null();
1811 cm->method()->print_value_on(&tempst);
1812 } else if (blob->is_runtime_stub()) {
1813 tempst.print("<runtime-stub>");
1814 } else {
1815 tempst.print("<unknown>");
1816 }
1817 tempst.print(" at " INTPTR_FORMAT, p2i(exception_pc));
1818 tempst.print("]");
1819
1820 st->print_raw_cr(tempst.freeze());
1821 }