1 /*
  2  * Copyright (c) 1999, 2024, 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 "code/SCCache.hpp"
 28 #include "compiler/compilationMemoryStatistic.hpp"
 29 #include "compiler/compilerDefinitions.inline.hpp"
 30 #include "runtime/handles.inline.hpp"
 31 #include "jfr/support/jfrIntrinsics.hpp"
 32 #include "opto/c2compiler.hpp"
 33 #include "opto/compile.hpp"
 34 #include "opto/optoreg.hpp"
 35 #include "opto/output.hpp"
 36 #include "opto/runtime.hpp"
 37 #include "runtime/stubRoutines.hpp"
 38 #include "runtime/globals_extension.hpp"
 39 #include "utilities/macros.hpp"
 40 
 41 
 42 // register information defined by ADLC
 43 extern const char register_save_policy[];
 44 extern const int  register_save_type[];
 45 
 46 const char* C2Compiler::retry_no_subsuming_loads() {
 47   return "retry without subsuming loads";
 48 }
 49 const char* C2Compiler::retry_no_escape_analysis() {
 50   return "retry without escape analysis";
 51 }
 52 const char* C2Compiler::retry_no_locks_coarsening() {
 53   return "retry without locks coarsening";
 54 }
 55 const char* C2Compiler::retry_no_iterative_escape_analysis() {
 56   return "retry without iterative escape analysis";
 57 }
 58 const char* C2Compiler::retry_no_reduce_allocation_merges() {
 59   return "retry without reducing allocation merges";
 60 }
 61 const char* C2Compiler::retry_no_superword() {
 62   return "retry without SuperWord";
 63 }
 64 
 65 const char* C2Compiler::retry_no_clinit_barriers() {
 66   return "retry without class initialization barriers";
 67 }
 68 
 69 void compiler_stubs_init(bool in_compiler_thread);
 70 
 71 bool C2Compiler::init_c2_runtime() {
 72 
 73 #ifdef ASSERT
 74   if (!AlignVector && VerifyAlignVector) {
 75     warning("VerifyAlignVector disabled because AlignVector is not enabled.");
 76     FLAG_SET_CMDLINE(VerifyAlignVector, false);
 77   }
 78 #endif
 79 
 80   // Check assumptions used while running ADLC
 81   Compile::adlc_verification();
 82   assert(REG_COUNT <= ConcreteRegisterImpl::number_of_registers, "incompatible register counts");
 83 
 84   for (int i = 0; i < ConcreteRegisterImpl::number_of_registers ; i++ ) {
 85       OptoReg::vm2opto[i] = OptoReg::Bad;
 86   }
 87 
 88   for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(REG_COUNT); i = OptoReg::add(i,1) ) {
 89     VMReg r = OptoReg::as_VMReg(i);
 90     if (r->is_valid()) {
 91       OptoReg::vm2opto[r->value()] = i;
 92     }
 93   }
 94 
 95   DEBUG_ONLY( Node::init_NodeProperty(); )
 96 
 97   compiler_stubs_init(true /* in_compiler_thread */); // generate compiler's intrinsics stubs
 98 
 99   Compile::pd_compiler2_init();
100 
101   CompilerThread* thread = CompilerThread::current();
102 
103   HandleMark handle_mark(thread);
104   bool success = OptoRuntime::generate(thread->env());
105   if (success) {
106     SCCache::init_opto_table();
107   }
108   return success;
109 }
110 
111 void C2Compiler::initialize() {
112   assert(!CompilerConfig::is_c1_or_interpreter_only_no_jvmci(), "C2 compiler is launched, it's not c1/interpreter only mode");
113   // The first compiler thread that gets here will initialize the
114   // small amount of global state (and runtime stubs) that C2 needs.
115 
116   // There is a race possible once at startup and then we're fine
117 
118   // Note that this is being called from a compiler thread not the
119   // main startup thread.
120   if (should_perform_init()) {
121     bool successful = C2Compiler::init_c2_runtime();
122     int new_state = (successful) ? initialized : failed;
123     set_state(new_state);
124   }
125 }
126 
127 void C2Compiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci, bool install_code, DirectiveSet* directive) {
128   assert(is_initialized(), "Compiler thread must be initialized");
129   CompilationMemoryStatisticMark cmsm(directive);
130   CompileTask* task = env->task();
131   if (install_code && task->is_scc()) {
132     bool success = SCCache::load_nmethod(env, target, entry_bci, this, CompLevel_full_optimization);
133     if (success) {
134       assert(task->is_success(), "sanity");
135       return;
136     }
137     if (!task->preload()) { // Do not mark entry if pre-loading failed - it can pass normal load
138       SCCache::invalidate(task->scc_entry()); // mark sca_entry as not entrant
139     }
140     if (SCCache::is_code_load_thread_on()) {
141       env->record_failure("Failed to load cached code");
142       // Bail out if failed to load cached code in SC thread
143       return;
144     }
145     task->clear_scc();
146   }
147 
148   bool subsume_loads = SubsumeLoads;
149   bool do_escape_analysis = DoEscapeAnalysis;
150   bool do_iterative_escape_analysis = DoEscapeAnalysis;
151   bool do_reduce_allocation_merges = ReduceAllocationMerges && EliminateAllocations;
152   bool eliminate_boxing = EliminateAutoBox;
153   bool do_locks_coarsening = EliminateLocks;
154   bool do_superword = UseSuperWord;
155   bool for_preload = (task->compile_reason() != CompileTask::Reason_Precompile) && // non-preload version is requested
156                      SCCache::gen_preload_code(target, entry_bci);
157   if (task->compile_reason() == CompileTask::Reason_PrecompileForPreload) {
158     assert(for_preload, "required");
159   }
160   while (!env->failing()) {
161     ResourceMark rm;
162     // Attempt to compile while subsuming loads into machine instructions.
163     Options options(subsume_loads,
164                     do_escape_analysis,
165                     do_iterative_escape_analysis,
166                     do_reduce_allocation_merges,
167                     eliminate_boxing,
168                     do_locks_coarsening,
169                     do_superword,
170                     for_preload,
171                     install_code);
172     Compile C(env, target, entry_bci, options, directive);
173 
174     // Check result and retry if appropriate.
175     if (C.failure_reason() != nullptr) {
176       if (C.failure_reason_is(retry_no_subsuming_loads())) {
177         assert(subsume_loads, "must make progress");
178         subsume_loads = false;
179         env->report_failure(C.failure_reason());
180         continue;  // retry
181       }
182       if (C.failure_reason_is(retry_no_escape_analysis())) {
183         assert(do_escape_analysis, "must make progress");
184         do_escape_analysis = false;
185         env->report_failure(C.failure_reason());
186         continue;  // retry
187       }
188       if (C.failure_reason_is(retry_no_iterative_escape_analysis())) {
189         assert(do_iterative_escape_analysis, "must make progress");
190         do_iterative_escape_analysis = false;
191         env->report_failure(C.failure_reason());
192         continue;  // retry
193       }
194       if (C.failure_reason_is(retry_no_reduce_allocation_merges())) {
195         assert(do_reduce_allocation_merges, "must make progress");
196         do_reduce_allocation_merges = false;
197         env->report_failure(C.failure_reason());
198         continue;  // retry
199       }
200       if (C.failure_reason_is(retry_no_locks_coarsening())) {
201         assert(do_locks_coarsening, "must make progress");
202         do_locks_coarsening = false;
203         env->report_failure(C.failure_reason());
204         continue;  // retry
205       }
206       if (C.failure_reason_is(retry_no_clinit_barriers())) {
207         assert(for_preload, "must make progress");
208         for_preload = false;
209         continue;
210       }
211       if (C.failure_reason_is(retry_no_superword())) {
212         assert(do_superword, "must make progress");
213         do_superword = false;
214         env->report_failure(C.failure_reason());
215         continue;  // retry
216       }
217       if (C.has_boxed_value()) {
218         // Recompile without boxing elimination regardless failure reason.
219         assert(eliminate_boxing, "must make progress");
220         eliminate_boxing = false;
221         env->report_failure(C.failure_reason());
222         continue;  // retry
223       }
224       // Pass any other failure reason up to the ciEnv.
225       // Note that serious, irreversible failures are already logged
226       // on the ciEnv via env->record_method_not_compilable().
227       env->record_failure(C.failure_reason());
228     }
229     if (StressRecompilation) {
230       if (subsume_loads) {
231         subsume_loads = false;
232         continue;  // retry
233       }
234       if (do_escape_analysis) {
235         do_escape_analysis = false;
236         continue;  // retry
237       }
238       if (do_locks_coarsening) {
239         do_locks_coarsening = false;
240         continue;  // retry
241       }
242     }
243     // print inlining for last compilation only
244     C.dump_print_inlining();
245 
246     // No retry; just break the loop.
247     break;
248   }
249 }
250 
251 void C2Compiler::print_timers() {
252   Compile::print_timers();
253 }
254 
255 bool C2Compiler::is_intrinsic_supported(const methodHandle& method) {
256   vmIntrinsics::ID id = method->intrinsic_id();
257   return C2Compiler::is_intrinsic_supported(id);
258 }
259 
260 bool C2Compiler::is_intrinsic_supported(vmIntrinsics::ID id) {
261   assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
262 
263   if (id < vmIntrinsics::FIRST_ID || id > vmIntrinsics::LAST_COMPILER_INLINE) {
264     return false;
265   }
266 
267   switch (id) {
268   case vmIntrinsics::_compressStringC:
269   case vmIntrinsics::_compressStringB:
270     if (!Matcher::match_rule_supported(Op_StrCompressedCopy)) return false;
271     break;
272   case vmIntrinsics::_inflateStringC:
273   case vmIntrinsics::_inflateStringB:
274     if (!Matcher::match_rule_supported(Op_StrInflatedCopy)) return false;
275     break;
276   case vmIntrinsics::_compareToL:
277   case vmIntrinsics::_compareToU:
278   case vmIntrinsics::_compareToLU:
279   case vmIntrinsics::_compareToUL:
280     if (!Matcher::match_rule_supported(Op_StrComp)) return false;
281     break;
282   case vmIntrinsics::_equalsL:
283     if (!Matcher::match_rule_supported(Op_StrEquals)) return false;
284     break;
285   case vmIntrinsics::_vectorizedHashCode:
286     if (!Matcher::match_rule_supported(Op_VectorizedHashCode)) return false;
287     break;
288   case vmIntrinsics::_equalsB:
289   case vmIntrinsics::_equalsC:
290     if (!Matcher::match_rule_supported(Op_AryEq)) return false;
291     break;
292   case vmIntrinsics::_copyMemory:
293     if (StubRoutines::unsafe_arraycopy() == nullptr) return false;
294     break;
295   case vmIntrinsics::_electronicCodeBook_encryptAESCrypt:
296     if (StubRoutines::electronicCodeBook_encryptAESCrypt() == nullptr) return false;
297     break;
298   case vmIntrinsics::_electronicCodeBook_decryptAESCrypt:
299     if (StubRoutines::electronicCodeBook_decryptAESCrypt() == nullptr) return false;
300     break;
301   case vmIntrinsics::_galoisCounterMode_AESCrypt:
302     if (StubRoutines::galoisCounterMode_AESCrypt() == nullptr) return false;
303     break;
304   case vmIntrinsics::_bigIntegerRightShiftWorker:
305     if (StubRoutines::bigIntegerRightShift() == nullptr) return false;
306     break;
307   case vmIntrinsics::_bigIntegerLeftShiftWorker:
308     if (StubRoutines::bigIntegerLeftShift() == nullptr) return false;
309     break;
310   case vmIntrinsics::_encodeAsciiArray:
311     if (!Matcher::match_rule_supported(Op_EncodeISOArray) || !Matcher::supports_encode_ascii_array) return false;
312     break;
313   case vmIntrinsics::_encodeISOArray:
314   case vmIntrinsics::_encodeByteISOArray:
315     if (!Matcher::match_rule_supported(Op_EncodeISOArray)) return false;
316     break;
317   case vmIntrinsics::_countPositives:
318     if (!Matcher::match_rule_supported(Op_CountPositives))  return false;
319     break;
320   case vmIntrinsics::_bitCount_i:
321     if (!Matcher::match_rule_supported(Op_PopCountI)) return false;
322     break;
323   case vmIntrinsics::_bitCount_l:
324     if (!Matcher::match_rule_supported(Op_PopCountL)) return false;
325     break;
326   case vmIntrinsics::_compress_i:
327   case vmIntrinsics::_compress_l:
328     if (!Matcher::match_rule_supported(Op_CompressBits)) return false;
329     break;
330   case vmIntrinsics::_expand_i:
331   case vmIntrinsics::_expand_l:
332     if (!Matcher::match_rule_supported(Op_ExpandBits)) return false;
333     break;
334   case vmIntrinsics::_numberOfLeadingZeros_i:
335     if (!Matcher::match_rule_supported(Op_CountLeadingZerosI)) return false;
336     break;
337   case vmIntrinsics::_numberOfLeadingZeros_l:
338     if (!Matcher::match_rule_supported(Op_CountLeadingZerosL)) return false;
339     break;
340   case vmIntrinsics::_numberOfTrailingZeros_i:
341     if (!Matcher::match_rule_supported(Op_CountTrailingZerosI)) return false;
342     break;
343   case vmIntrinsics::_numberOfTrailingZeros_l:
344     if (!Matcher::match_rule_supported(Op_CountTrailingZerosL)) return false;
345     break;
346   case vmIntrinsics::_reverse_i:
347     if (!Matcher::match_rule_supported(Op_ReverseI)) return false;
348     break;
349   case vmIntrinsics::_reverse_l:
350     if (!Matcher::match_rule_supported(Op_ReverseL)) return false;
351     break;
352   case vmIntrinsics::_reverseBytes_c:
353     if (!Matcher::match_rule_supported(Op_ReverseBytesUS)) return false;
354     break;
355   case vmIntrinsics::_reverseBytes_s:
356     if (!Matcher::match_rule_supported(Op_ReverseBytesS)) return false;
357     break;
358   case vmIntrinsics::_reverseBytes_i:
359     if (!Matcher::match_rule_supported(Op_ReverseBytesI)) return false;
360     break;
361   case vmIntrinsics::_reverseBytes_l:
362     if (!Matcher::match_rule_supported(Op_ReverseBytesL)) return false;
363     break;
364   case vmIntrinsics::_compareUnsigned_i:
365     if (!Matcher::match_rule_supported(Op_CmpU3)) return false;
366     break;
367   case vmIntrinsics::_compareUnsigned_l:
368     if (!Matcher::match_rule_supported(Op_CmpUL3)) return false;
369     break;
370   case vmIntrinsics::_divideUnsigned_i:
371     if (!Matcher::match_rule_supported(Op_UDivI)) return false;
372     break;
373   case vmIntrinsics::_remainderUnsigned_i:
374     if (!Matcher::match_rule_supported(Op_UModI)) return false;
375     break;
376   case vmIntrinsics::_divideUnsigned_l:
377     if (!Matcher::match_rule_supported(Op_UDivL)) return false;
378     break;
379   case vmIntrinsics::_remainderUnsigned_l:
380     if (!Matcher::match_rule_supported(Op_UModL)) return false;
381     break;
382   case vmIntrinsics::_float16ToFloat:
383     if (!Matcher::match_rule_supported(Op_ConvHF2F)) return false;
384     break;
385   case vmIntrinsics::_floatToFloat16:
386     if (!Matcher::match_rule_supported(Op_ConvF2HF)) return false;
387     break;
388 
389   /* CompareAndSet, Object: */
390   case vmIntrinsics::_compareAndSetReference:
391 #ifdef _LP64
392     if ( UseCompressedOops && !Matcher::match_rule_supported(Op_CompareAndSwapN)) return false;
393     if (!UseCompressedOops && !Matcher::match_rule_supported(Op_CompareAndSwapP)) return false;
394 #else
395     if (!Matcher::match_rule_supported(Op_CompareAndSwapP)) return false;
396 #endif
397     break;
398   case vmIntrinsics::_weakCompareAndSetReferencePlain:
399   case vmIntrinsics::_weakCompareAndSetReferenceAcquire:
400   case vmIntrinsics::_weakCompareAndSetReferenceRelease:
401   case vmIntrinsics::_weakCompareAndSetReference:
402 #ifdef _LP64
403     if ( UseCompressedOops && !Matcher::match_rule_supported(Op_WeakCompareAndSwapN)) return false;
404     if (!UseCompressedOops && !Matcher::match_rule_supported(Op_WeakCompareAndSwapP)) return false;
405 #else
406     if (!Matcher::match_rule_supported(Op_WeakCompareAndSwapP)) return false;
407 #endif
408     break;
409   /* CompareAndSet, Long: */
410   case vmIntrinsics::_compareAndSetLong:
411     if (!Matcher::match_rule_supported(Op_CompareAndSwapL)) return false;
412     break;
413   case vmIntrinsics::_weakCompareAndSetLongPlain:
414   case vmIntrinsics::_weakCompareAndSetLongAcquire:
415   case vmIntrinsics::_weakCompareAndSetLongRelease:
416   case vmIntrinsics::_weakCompareAndSetLong:
417     if (!Matcher::match_rule_supported(Op_WeakCompareAndSwapL)) return false;
418     break;
419 
420   /* CompareAndSet, Int: */
421   case vmIntrinsics::_compareAndSetInt:
422     if (!Matcher::match_rule_supported(Op_CompareAndSwapI)) return false;
423     break;
424   case vmIntrinsics::_weakCompareAndSetIntPlain:
425   case vmIntrinsics::_weakCompareAndSetIntAcquire:
426   case vmIntrinsics::_weakCompareAndSetIntRelease:
427   case vmIntrinsics::_weakCompareAndSetInt:
428     if (!Matcher::match_rule_supported(Op_WeakCompareAndSwapI)) return false;
429     break;
430 
431   /* CompareAndSet, Byte: */
432   case vmIntrinsics::_compareAndSetByte:
433     if (!Matcher::match_rule_supported(Op_CompareAndSwapB)) return false;
434     break;
435   case vmIntrinsics::_weakCompareAndSetBytePlain:
436   case vmIntrinsics::_weakCompareAndSetByteAcquire:
437   case vmIntrinsics::_weakCompareAndSetByteRelease:
438   case vmIntrinsics::_weakCompareAndSetByte:
439     if (!Matcher::match_rule_supported(Op_WeakCompareAndSwapB)) return false;
440     break;
441 
442   /* CompareAndSet, Short: */
443   case vmIntrinsics::_compareAndSetShort:
444     if (!Matcher::match_rule_supported(Op_CompareAndSwapS)) return false;
445     break;
446   case vmIntrinsics::_weakCompareAndSetShortPlain:
447   case vmIntrinsics::_weakCompareAndSetShortAcquire:
448   case vmIntrinsics::_weakCompareAndSetShortRelease:
449   case vmIntrinsics::_weakCompareAndSetShort:
450     if (!Matcher::match_rule_supported(Op_WeakCompareAndSwapS)) return false;
451     break;
452 
453   /* CompareAndExchange, Object: */
454   case vmIntrinsics::_compareAndExchangeReference:
455   case vmIntrinsics::_compareAndExchangeReferenceAcquire:
456   case vmIntrinsics::_compareAndExchangeReferenceRelease:
457 #ifdef _LP64
458     if ( UseCompressedOops && !Matcher::match_rule_supported(Op_CompareAndExchangeN)) return false;
459     if (!UseCompressedOops && !Matcher::match_rule_supported(Op_CompareAndExchangeP)) return false;
460 #else
461     if (!Matcher::match_rule_supported(Op_CompareAndExchangeP)) return false;
462 #endif
463     break;
464 
465   /* CompareAndExchange, Long: */
466   case vmIntrinsics::_compareAndExchangeLong:
467   case vmIntrinsics::_compareAndExchangeLongAcquire:
468   case vmIntrinsics::_compareAndExchangeLongRelease:
469     if (!Matcher::match_rule_supported(Op_CompareAndExchangeL)) return false;
470     break;
471 
472   /* CompareAndExchange, Int: */
473   case vmIntrinsics::_compareAndExchangeInt:
474   case vmIntrinsics::_compareAndExchangeIntAcquire:
475   case vmIntrinsics::_compareAndExchangeIntRelease:
476     if (!Matcher::match_rule_supported(Op_CompareAndExchangeI)) return false;
477     break;
478 
479   /* CompareAndExchange, Byte: */
480   case vmIntrinsics::_compareAndExchangeByte:
481   case vmIntrinsics::_compareAndExchangeByteAcquire:
482   case vmIntrinsics::_compareAndExchangeByteRelease:
483     if (!Matcher::match_rule_supported(Op_CompareAndExchangeB)) return false;
484     break;
485 
486   /* CompareAndExchange, Short: */
487   case vmIntrinsics::_compareAndExchangeShort:
488   case vmIntrinsics::_compareAndExchangeShortAcquire:
489   case vmIntrinsics::_compareAndExchangeShortRelease:
490     if (!Matcher::match_rule_supported(Op_CompareAndExchangeS)) return false;
491     break;
492 
493   case vmIntrinsics::_getAndAddByte:
494     if (!Matcher::match_rule_supported(Op_GetAndAddB)) return false;
495     break;
496   case vmIntrinsics::_getAndAddShort:
497     if (!Matcher::match_rule_supported(Op_GetAndAddS)) return false;
498     break;
499   case vmIntrinsics::_getAndAddInt:
500     if (!Matcher::match_rule_supported(Op_GetAndAddI)) return false;
501     break;
502   case vmIntrinsics::_getAndAddLong:
503     if (!Matcher::match_rule_supported(Op_GetAndAddL)) return false;
504     break;
505 
506   case vmIntrinsics::_getAndSetByte:
507     if (!Matcher::match_rule_supported(Op_GetAndSetB)) return false;
508     break;
509   case vmIntrinsics::_getAndSetShort:
510     if (!Matcher::match_rule_supported(Op_GetAndSetS)) return false;
511     break;
512   case vmIntrinsics::_getAndSetInt:
513     if (!Matcher::match_rule_supported(Op_GetAndSetI)) return false;
514     break;
515   case vmIntrinsics::_getAndSetLong:
516     if (!Matcher::match_rule_supported(Op_GetAndSetL)) return false;
517     break;
518   case vmIntrinsics::_getAndSetReference:
519 #ifdef _LP64
520     if (!UseCompressedOops && !Matcher::match_rule_supported(Op_GetAndSetP)) return false;
521     if (UseCompressedOops && !Matcher::match_rule_supported(Op_GetAndSetN)) return false;
522     break;
523 #else
524     if (!Matcher::match_rule_supported(Op_GetAndSetP)) return false;
525     break;
526 #endif
527   case vmIntrinsics::_incrementExactI:
528   case vmIntrinsics::_addExactI:
529     if (!Matcher::match_rule_supported(Op_OverflowAddI)) return false;
530     break;
531   case vmIntrinsics::_incrementExactL:
532   case vmIntrinsics::_addExactL:
533     if (!Matcher::match_rule_supported(Op_OverflowAddL)) return false;
534     break;
535   case vmIntrinsics::_decrementExactI:
536   case vmIntrinsics::_subtractExactI:
537     if (!Matcher::match_rule_supported(Op_OverflowSubI)) return false;
538     break;
539   case vmIntrinsics::_decrementExactL:
540   case vmIntrinsics::_subtractExactL:
541     if (!Matcher::match_rule_supported(Op_OverflowSubL)) return false;
542     break;
543   case vmIntrinsics::_negateExactI:
544     if (!Matcher::match_rule_supported(Op_OverflowSubI)) return false;
545     break;
546   case vmIntrinsics::_negateExactL:
547     if (!Matcher::match_rule_supported(Op_OverflowSubL)) return false;
548     break;
549   case vmIntrinsics::_multiplyExactI:
550     if (!Matcher::match_rule_supported(Op_OverflowMulI)) return false;
551     break;
552   case vmIntrinsics::_multiplyExactL:
553     if (!Matcher::match_rule_supported(Op_OverflowMulL)) return false;
554     break;
555   case vmIntrinsics::_multiplyHigh:
556     if (!Matcher::match_rule_supported(Op_MulHiL)) return false;
557     break;
558   case vmIntrinsics::_unsignedMultiplyHigh:
559     if (!Matcher::match_rule_supported(Op_UMulHiL)) return false;
560     break;
561   case vmIntrinsics::_getCallerClass:
562     if (vmClasses::reflect_CallerSensitive_klass() == nullptr) return false;
563     break;
564   case vmIntrinsics::_onSpinWait:
565     if (!Matcher::match_rule_supported(Op_OnSpinWait)) return false;
566     break;
567   case vmIntrinsics::_fmaD:
568     if (!Matcher::match_rule_supported(Op_FmaD)) return false;
569     break;
570   case vmIntrinsics::_fmaF:
571     if (!Matcher::match_rule_supported(Op_FmaF)) return false;
572     break;
573   case vmIntrinsics::_isDigit:
574     if (!Matcher::match_rule_supported(Op_Digit)) return false;
575     break;
576   case vmIntrinsics::_isLowerCase:
577     if (!Matcher::match_rule_supported(Op_LowerCase)) return false;
578     break;
579   case vmIntrinsics::_isUpperCase:
580     if (!Matcher::match_rule_supported(Op_UpperCase)) return false;
581     break;
582   case vmIntrinsics::_isWhitespace:
583     if (!Matcher::match_rule_supported(Op_Whitespace)) return false;
584     break;
585   case vmIntrinsics::_maxF:
586   case vmIntrinsics::_maxF_strict:
587     if (!Matcher::match_rule_supported(Op_MaxF)) return false;
588     break;
589   case vmIntrinsics::_minF:
590   case vmIntrinsics::_minF_strict:
591     if (!Matcher::match_rule_supported(Op_MinF)) return false;
592     break;
593   case vmIntrinsics::_maxD:
594   case vmIntrinsics::_maxD_strict:
595     if (!Matcher::match_rule_supported(Op_MaxD)) return false;
596     break;
597   case vmIntrinsics::_minD:
598   case vmIntrinsics::_minD_strict:
599     if (!Matcher::match_rule_supported(Op_MinD)) return false;
600     break;
601   case vmIntrinsics::_writeback0:
602     if (!Matcher::match_rule_supported(Op_CacheWB)) return false;
603     break;
604   case vmIntrinsics::_writebackPreSync0:
605     if (!Matcher::match_rule_supported(Op_CacheWBPreSync)) return false;
606     break;
607   case vmIntrinsics::_writebackPostSync0:
608     if (!Matcher::match_rule_supported(Op_CacheWBPostSync)) return false;
609     break;
610   case vmIntrinsics::_rint:
611   case vmIntrinsics::_ceil:
612   case vmIntrinsics::_floor:
613     if (!Matcher::match_rule_supported(Op_RoundDoubleMode)) return false;
614     break;
615   case vmIntrinsics::_dcopySign:
616     if (!Matcher::match_rule_supported(Op_CopySignD)) return false;
617     break;
618   case vmIntrinsics::_fcopySign:
619     if (!Matcher::match_rule_supported(Op_CopySignF)) return false;
620     break;
621   case vmIntrinsics::_dsignum:
622     if (!Matcher::match_rule_supported(Op_SignumD)) return false;
623     break;
624   case vmIntrinsics::_fsignum:
625     if (!Matcher::match_rule_supported(Op_SignumF)) return false;
626     break;
627   case vmIntrinsics::_floatIsInfinite:
628     if (!Matcher::match_rule_supported(Op_IsInfiniteF)) return false;
629     break;
630   case vmIntrinsics::_floatIsFinite:
631     if (!Matcher::match_rule_supported(Op_IsFiniteF)) return false;
632     break;
633   case vmIntrinsics::_doubleIsInfinite:
634     if (!Matcher::match_rule_supported(Op_IsInfiniteD)) return false;
635     break;
636   case vmIntrinsics::_doubleIsFinite:
637     if (!Matcher::match_rule_supported(Op_IsFiniteD)) return false;
638     break;
639   case vmIntrinsics::_hashCode:
640   case vmIntrinsics::_identityHashCode:
641   case vmIntrinsics::_getClass:
642   case vmIntrinsics::_dsin:
643   case vmIntrinsics::_dcos:
644   case vmIntrinsics::_dtan:
645   case vmIntrinsics::_dabs:
646   case vmIntrinsics::_fabs:
647   case vmIntrinsics::_iabs:
648   case vmIntrinsics::_labs:
649   case vmIntrinsics::_datan2:
650   case vmIntrinsics::_dsqrt:
651   case vmIntrinsics::_dsqrt_strict:
652   case vmIntrinsics::_dexp:
653   case vmIntrinsics::_dlog:
654   case vmIntrinsics::_dlog10:
655   case vmIntrinsics::_dpow:
656   case vmIntrinsics::_roundD:
657   case vmIntrinsics::_roundF:
658   case vmIntrinsics::_min:
659   case vmIntrinsics::_max:
660   case vmIntrinsics::_min_strict:
661   case vmIntrinsics::_max_strict:
662   case vmIntrinsics::_arraycopy:
663   case vmIntrinsics::_arraySort:
664   case vmIntrinsics::_arrayPartition:
665   case vmIntrinsics::_indexOfL:
666   case vmIntrinsics::_indexOfU:
667   case vmIntrinsics::_indexOfUL:
668   case vmIntrinsics::_indexOfIL:
669   case vmIntrinsics::_indexOfIU:
670   case vmIntrinsics::_indexOfIUL:
671   case vmIntrinsics::_indexOfU_char:
672   case vmIntrinsics::_indexOfL_char:
673   case vmIntrinsics::_toBytesStringU:
674   case vmIntrinsics::_getCharsStringU:
675   case vmIntrinsics::_getCharStringU:
676   case vmIntrinsics::_putCharStringU:
677   case vmIntrinsics::_getReference:
678   case vmIntrinsics::_getBoolean:
679   case vmIntrinsics::_getByte:
680   case vmIntrinsics::_getShort:
681   case vmIntrinsics::_getChar:
682   case vmIntrinsics::_getInt:
683   case vmIntrinsics::_getLong:
684   case vmIntrinsics::_getFloat:
685   case vmIntrinsics::_getDouble:
686   case vmIntrinsics::_putReference:
687   case vmIntrinsics::_putBoolean:
688   case vmIntrinsics::_putByte:
689   case vmIntrinsics::_putShort:
690   case vmIntrinsics::_putChar:
691   case vmIntrinsics::_putInt:
692   case vmIntrinsics::_putLong:
693   case vmIntrinsics::_putFloat:
694   case vmIntrinsics::_putDouble:
695   case vmIntrinsics::_getReferenceVolatile:
696   case vmIntrinsics::_getBooleanVolatile:
697   case vmIntrinsics::_getByteVolatile:
698   case vmIntrinsics::_getShortVolatile:
699   case vmIntrinsics::_getCharVolatile:
700   case vmIntrinsics::_getIntVolatile:
701   case vmIntrinsics::_getLongVolatile:
702   case vmIntrinsics::_getFloatVolatile:
703   case vmIntrinsics::_getDoubleVolatile:
704   case vmIntrinsics::_putReferenceVolatile:
705   case vmIntrinsics::_putBooleanVolatile:
706   case vmIntrinsics::_putByteVolatile:
707   case vmIntrinsics::_putShortVolatile:
708   case vmIntrinsics::_putCharVolatile:
709   case vmIntrinsics::_putIntVolatile:
710   case vmIntrinsics::_putLongVolatile:
711   case vmIntrinsics::_putFloatVolatile:
712   case vmIntrinsics::_putDoubleVolatile:
713   case vmIntrinsics::_getReferenceAcquire:
714   case vmIntrinsics::_getBooleanAcquire:
715   case vmIntrinsics::_getByteAcquire:
716   case vmIntrinsics::_getShortAcquire:
717   case vmIntrinsics::_getCharAcquire:
718   case vmIntrinsics::_getIntAcquire:
719   case vmIntrinsics::_getLongAcquire:
720   case vmIntrinsics::_getFloatAcquire:
721   case vmIntrinsics::_getDoubleAcquire:
722   case vmIntrinsics::_putReferenceRelease:
723   case vmIntrinsics::_putBooleanRelease:
724   case vmIntrinsics::_putByteRelease:
725   case vmIntrinsics::_putShortRelease:
726   case vmIntrinsics::_putCharRelease:
727   case vmIntrinsics::_putIntRelease:
728   case vmIntrinsics::_putLongRelease:
729   case vmIntrinsics::_putFloatRelease:
730   case vmIntrinsics::_putDoubleRelease:
731   case vmIntrinsics::_getReferenceOpaque:
732   case vmIntrinsics::_getBooleanOpaque:
733   case vmIntrinsics::_getByteOpaque:
734   case vmIntrinsics::_getShortOpaque:
735   case vmIntrinsics::_getCharOpaque:
736   case vmIntrinsics::_getIntOpaque:
737   case vmIntrinsics::_getLongOpaque:
738   case vmIntrinsics::_getFloatOpaque:
739   case vmIntrinsics::_getDoubleOpaque:
740   case vmIntrinsics::_putReferenceOpaque:
741   case vmIntrinsics::_putBooleanOpaque:
742   case vmIntrinsics::_putByteOpaque:
743   case vmIntrinsics::_putShortOpaque:
744   case vmIntrinsics::_putCharOpaque:
745   case vmIntrinsics::_putIntOpaque:
746   case vmIntrinsics::_putLongOpaque:
747   case vmIntrinsics::_putFloatOpaque:
748   case vmIntrinsics::_putDoubleOpaque:
749   case vmIntrinsics::_getShortUnaligned:
750   case vmIntrinsics::_getCharUnaligned:
751   case vmIntrinsics::_getIntUnaligned:
752   case vmIntrinsics::_getLongUnaligned:
753   case vmIntrinsics::_putShortUnaligned:
754   case vmIntrinsics::_putCharUnaligned:
755   case vmIntrinsics::_putIntUnaligned:
756   case vmIntrinsics::_putLongUnaligned:
757   case vmIntrinsics::_loadFence:
758   case vmIntrinsics::_storeFence:
759   case vmIntrinsics::_storeStoreFence:
760   case vmIntrinsics::_fullFence:
761   case vmIntrinsics::_currentCarrierThread:
762   case vmIntrinsics::_currentThread:
763   case vmIntrinsics::_setCurrentThread:
764   case vmIntrinsics::_scopedValueCache:
765   case vmIntrinsics::_setScopedValueCache:
766 #ifdef JFR_HAVE_INTRINSICS
767   case vmIntrinsics::_counterTime:
768   case vmIntrinsics::_getEventWriter:
769   case vmIntrinsics::_jvm_commit:
770 #endif
771   case vmIntrinsics::_currentTimeMillis:
772   case vmIntrinsics::_nanoTime:
773   case vmIntrinsics::_allocateInstance:
774   case vmIntrinsics::_allocateUninitializedArray:
775   case vmIntrinsics::_newArray:
776   case vmIntrinsics::_getLength:
777   case vmIntrinsics::_copyOf:
778   case vmIntrinsics::_copyOfRange:
779   case vmIntrinsics::_clone:
780   case vmIntrinsics::_isAssignableFrom:
781   case vmIntrinsics::_isInstance:
782   case vmIntrinsics::_getModifiers:
783   case vmIntrinsics::_isInterface:
784   case vmIntrinsics::_isArray:
785   case vmIntrinsics::_isPrimitive:
786   case vmIntrinsics::_isHidden:
787   case vmIntrinsics::_getSuperclass:
788   case vmIntrinsics::_getClassAccessFlags:
789   case vmIntrinsics::_floatToRawIntBits:
790   case vmIntrinsics::_floatToIntBits:
791   case vmIntrinsics::_intBitsToFloat:
792   case vmIntrinsics::_doubleToRawLongBits:
793   case vmIntrinsics::_doubleToLongBits:
794   case vmIntrinsics::_longBitsToDouble:
795   case vmIntrinsics::_Reference_get:
796   case vmIntrinsics::_Reference_refersTo0:
797   case vmIntrinsics::_PhantomReference_refersTo0:
798   case vmIntrinsics::_Class_cast:
799   case vmIntrinsics::_aescrypt_encryptBlock:
800   case vmIntrinsics::_aescrypt_decryptBlock:
801   case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
802   case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
803   case vmIntrinsics::_counterMode_AESCrypt:
804   case vmIntrinsics::_md5_implCompress:
805   case vmIntrinsics::_sha_implCompress:
806   case vmIntrinsics::_sha2_implCompress:
807   case vmIntrinsics::_sha5_implCompress:
808   case vmIntrinsics::_sha3_implCompress:
809   case vmIntrinsics::_digestBase_implCompressMB:
810   case vmIntrinsics::_multiplyToLen:
811   case vmIntrinsics::_squareToLen:
812   case vmIntrinsics::_mulAdd:
813   case vmIntrinsics::_montgomeryMultiply:
814   case vmIntrinsics::_montgomerySquare:
815   case vmIntrinsics::_vectorizedMismatch:
816   case vmIntrinsics::_ghash_processBlocks:
817   case vmIntrinsics::_chacha20Block:
818   case vmIntrinsics::_base64_encodeBlock:
819   case vmIntrinsics::_base64_decodeBlock:
820   case vmIntrinsics::_poly1305_processBlocks:
821   case vmIntrinsics::_updateCRC32:
822   case vmIntrinsics::_updateBytesCRC32:
823   case vmIntrinsics::_updateByteBufferCRC32:
824   case vmIntrinsics::_updateBytesCRC32C:
825   case vmIntrinsics::_updateDirectByteBufferCRC32C:
826   case vmIntrinsics::_updateBytesAdler32:
827   case vmIntrinsics::_updateByteBufferAdler32:
828   case vmIntrinsics::_profileBoolean:
829   case vmIntrinsics::_isCompileConstant:
830   case vmIntrinsics::_Preconditions_checkIndex:
831   case vmIntrinsics::_Preconditions_checkLongIndex:
832   case vmIntrinsics::_getObjectSize:
833     break;
834   case vmIntrinsics::_VectorCompressExpand:
835   case vmIntrinsics::_VectorUnaryOp:
836   case vmIntrinsics::_VectorBinaryOp:
837   case vmIntrinsics::_VectorTernaryOp:
838   case vmIntrinsics::_VectorFromBitsCoerced:
839   case vmIntrinsics::_VectorShuffleIota:
840   case vmIntrinsics::_VectorShuffleToVector:
841   case vmIntrinsics::_VectorLoadOp:
842   case vmIntrinsics::_VectorLoadMaskedOp:
843   case vmIntrinsics::_VectorStoreOp:
844   case vmIntrinsics::_VectorStoreMaskedOp:
845   case vmIntrinsics::_VectorGatherOp:
846   case vmIntrinsics::_VectorScatterOp:
847   case vmIntrinsics::_VectorReductionCoerced:
848   case vmIntrinsics::_VectorTest:
849   case vmIntrinsics::_VectorBlend:
850   case vmIntrinsics::_VectorRearrange:
851   case vmIntrinsics::_VectorCompare:
852   case vmIntrinsics::_VectorBroadcastInt:
853   case vmIntrinsics::_VectorConvert:
854   case vmIntrinsics::_VectorInsert:
855   case vmIntrinsics::_VectorExtract:
856   case vmIntrinsics::_VectorMaskOp:
857   case vmIntrinsics::_IndexVector:
858   case vmIntrinsics::_IndexPartiallyInUpperRange:
859     return EnableVectorSupport;
860   case vmIntrinsics::_blackhole:
861 #if INCLUDE_JVMTI
862   case vmIntrinsics::_notifyJvmtiVThreadStart:
863   case vmIntrinsics::_notifyJvmtiVThreadEnd:
864   case vmIntrinsics::_notifyJvmtiVThreadMount:
865   case vmIntrinsics::_notifyJvmtiVThreadUnmount:
866   case vmIntrinsics::_notifyJvmtiVThreadHideFrames:
867   case vmIntrinsics::_notifyJvmtiVThreadDisableSuspend:
868 #endif
869     break;
870 
871   default:
872     return false;
873   }
874   return true;
875 }
876 
877 int C2Compiler::initial_code_buffer_size(int const_size) {
878   // See Compile::init_scratch_buffer_blob
879   int locs_size = sizeof(relocInfo) * PhaseOutput::MAX_locs_size;
880   int slop = 2 * CodeSection::end_slop(); // space between sections
881   return PhaseOutput::MAX_inst_size + PhaseOutput::MAX_stubs_size + const_size + slop + locs_size;
882 }