1 /*
  2  * Copyright (c) 2022, 2026, 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 "cds/aotClassLinker.hpp"
 26 #include "cds/aotConstantPoolResolver.hpp"
 27 #include "cds/archiveBuilder.hpp"
 28 #include "cds/cdsConfig.hpp"
 29 #include "classfile/systemDictionary.hpp"
 30 #include "classfile/systemDictionaryShared.hpp"
 31 #include "classfile/vmClasses.hpp"
 32 #include "interpreter/bytecodeStream.hpp"
 33 #include "interpreter/interpreterRuntime.hpp"
 34 #include "memory/resourceArea.hpp"
 35 #include "oops/constantPool.inline.hpp"
 36 #include "oops/instanceKlass.hpp"
 37 #include "oops/klass.inline.hpp"
 38 #include "runtime/handles.inline.hpp"
 39 
 40 // Returns true if we CAN PROVE that cp_index will always resolve to
 41 // the same information at both dump time and run time. This is a
 42 // necessary (but not sufficient) condition for pre-resolving cp_index
 43 // during CDS archive assembly.
 44 bool AOTConstantPoolResolver::is_resolution_deterministic(ConstantPool* cp, int cp_index) {
 45   assert(!is_in_archivebuilder_buffer(cp), "sanity");
 46 
 47   if (cp->tag_at(cp_index).is_klass()) {
 48     // We require cp_index to be already resolved. This is fine for now, are we
 49     // currently archive only CP entries that are already resolved.
 50     Klass* resolved_klass = cp->resolved_klass_at(cp_index);
 51     return resolved_klass != nullptr && is_class_resolution_deterministic(cp->pool_holder(), resolved_klass);
 52   } else if (cp->tag_at(cp_index).is_invoke_dynamic()) {
 53     return is_indy_resolution_deterministic(cp, cp_index);
 54   } else if (cp->tag_at(cp_index).is_field() ||
 55              cp->tag_at(cp_index).is_method() ||
 56              cp->tag_at(cp_index).is_interface_method()) {
 57     int klass_cp_index = cp->uncached_klass_ref_index_at(cp_index);
 58     if (!cp->tag_at(klass_cp_index).is_klass()) {
 59       // Not yet resolved
 60       return false;
 61     }
 62     Klass* k = cp->resolved_klass_at(klass_cp_index);
 63     if (!is_class_resolution_deterministic(cp->pool_holder(), k)) {
 64       return false;
 65     }
 66 
 67     if (!k->is_instance_klass()) {
 68       // TODO: support non instance klasses as well.
 69       return false;
 70     }
 71 
 72     // Here, We don't check if this entry can actually be resolved to a valid Field/Method.
 73     // This method should be called by the ConstantPool to check Fields/Methods that
 74     // have already been successfully resolved.
 75     return true;
 76   } else {
 77     return false;
 78   }
 79 }
 80 
 81 bool AOTConstantPoolResolver::is_class_resolution_deterministic(InstanceKlass* cp_holder, Klass* resolved_class) {
 82   assert(!is_in_archivebuilder_buffer(cp_holder), "sanity");
 83   assert(!is_in_archivebuilder_buffer(resolved_class), "sanity");
 84 
 85   if (resolved_class->is_instance_klass()) {
 86     InstanceKlass* ik = InstanceKlass::cast(resolved_class);
 87 
 88     if (!ik->in_aot_cache() && SystemDictionaryShared::is_excluded_class(ik)) {
 89       return false;
 90     }
 91 
 92     if (cp_holder->is_subtype_of(ik)) {
 93       // All super types of ik will be resolved in ik->class_loader() before
 94       // ik is defined in this loader, so it's safe to archive the resolved klass reference.
 95       return true;
 96     }
 97 
 98     if (CDSConfig::is_dumping_aot_linked_classes()) {
 99       // Need to call try_add_candidate instead of is_candidate, as this may be called
100       // before AOTClassLinker::add_candidates().
101       if (AOTClassLinker::try_add_candidate(ik)) {
102         return true;
103       } else {
104         return false;
105       }
106     } else if (AOTClassLinker::is_vm_class(ik)) {
107       if (ik->class_loader() != cp_holder->class_loader()) {
108         // At runtime, cp_holder() may not be able to resolve to the same
109         // ik. For example, a different version of ik may be defined in
110         // cp->pool_holder()'s loader using MethodHandles.Lookup.defineClass().
111         return false;
112       } else {
113         return true;
114       }
115     } else {
116       return false;
117     }
118   } else if (resolved_class->is_objArray_klass()) {
119     if (CDSConfig::is_dumping_dynamic_archive()) {
120       // This is difficult to handle. See JDK-8374639
121       return false;
122     }
123     Klass* elem = ObjArrayKlass::cast(resolved_class)->bottom_klass();
124     if (elem->is_instance_klass()) {
125       return is_class_resolution_deterministic(cp_holder, InstanceKlass::cast(elem));
126     } else if (elem->is_typeArray_klass()) {
127       return true;
128     } else {
129       return false;
130     }
131   } else if (resolved_class->is_typeArray_klass()) {
132     return true;
133   } else {
134     return false;
135   }
136 }
137 
138 void AOTConstantPoolResolver::preresolve_string_cp_entries(InstanceKlass* ik, TRAPS) {
139   if (!ik->is_linked()) {
140     // The cp->resolved_referenced() array is not ready yet, so we can't call resolve_string().
141     return;
142   }
143   constantPoolHandle cp(THREAD, ik->constants());
144   for (int cp_index = 1; cp_index < cp->length(); cp_index++) { // Index 0 is unused
145     switch (cp->tag_at(cp_index).value()) {
146     case JVM_CONSTANT_String:
147       resolve_string(cp, cp_index, CHECK); // may throw OOM when interning strings.
148       break;
149     }
150   }
151 }
152 
153 // This works only for the boot/platform/app loaders
154 Klass* AOTConstantPoolResolver::find_loaded_class(Thread* current, oop class_loader, Symbol* name) {
155   HandleMark hm(current);
156   Handle h_loader(current, class_loader);
157   Klass* k = SystemDictionary::find_instance_or_array_klass(current, name, h_loader);
158   if (k != nullptr) {
159     return k;
160   }
161   if (h_loader() == SystemDictionary::java_system_loader()) {
162     return find_loaded_class(current, SystemDictionary::java_platform_loader(), name);
163   } else if (h_loader() == SystemDictionary::java_platform_loader()) {
164     return find_loaded_class(current, nullptr, name);
165   } else {
166     assert(h_loader() == nullptr, "This function only works for boot/platform/app loaders %p %p %p",
167            cast_from_oop<address>(h_loader()),
168            cast_from_oop<address>(SystemDictionary::java_system_loader()),
169            cast_from_oop<address>(SystemDictionary::java_platform_loader()));
170   }
171 
172   return nullptr;
173 }
174 
175 Klass* AOTConstantPoolResolver::find_loaded_class(Thread* current, ConstantPool* cp, int class_cp_index) {
176   Symbol* name = cp->klass_name_at(class_cp_index);
177   return find_loaded_class(current, cp->pool_holder()->class_loader(), name);
178 }
179 
180 #if INCLUDE_CDS_JAVA_HEAP
181 void AOTConstantPoolResolver::resolve_string(constantPoolHandle cp, int cp_index, TRAPS) {
182   if (CDSConfig::is_dumping_heap()) {
183     int cache_index = cp->cp_to_object_index(cp_index);
184     ConstantPool::string_at_impl(cp, cp_index, cache_index, CHECK);
185   }
186 }
187 #endif
188 
189 void AOTConstantPoolResolver::preresolve_class_cp_entries(JavaThread* current, InstanceKlass* ik, GrowableArray<bool>* preresolve_list) {
190   if (!SystemDictionaryShared::is_builtin_loader(ik->class_loader_data())) {
191     return;
192   }
193 
194   JavaThread* THREAD = current;
195   constantPoolHandle cp(THREAD, ik->constants());
196   for (int cp_index = 1; cp_index < cp->length(); cp_index++) {
197     if (cp->tag_at(cp_index).value() == JVM_CONSTANT_UnresolvedClass) {
198       if (preresolve_list != nullptr && preresolve_list->at(cp_index) == false) {
199         // This class was not resolved during trial run. Don't attempt to resolve it. Otherwise
200         // the compiler may generate less efficient code.
201         continue;
202       }
203       if (find_loaded_class(current, cp(), cp_index) == nullptr) {
204         // Do not resolve any class that has not been loaded yet
205         continue;
206       }
207       Klass* resolved_klass = cp->klass_at(cp_index, THREAD);
208       if (HAS_PENDING_EXCEPTION) {
209         CLEAR_PENDING_EXCEPTION; // just ignore
210       } else {
211         log_trace(aot, resolve)("Resolved class  [%3d] %s -> %s", cp_index, ik->external_name(),
212                                 resolved_klass->external_name());
213       }
214     }
215   }
216 }
217 
218 void AOTConstantPoolResolver::preresolve_field_and_method_cp_entries(JavaThread* current, InstanceKlass* ik, GrowableArray<bool>* preresolve_list) {
219   JavaThread* THREAD = current;
220   constantPoolHandle cp(THREAD, ik->constants());
221   if (cp->cache() == nullptr) {
222     return;
223   }
224   for (int i = 0; i < ik->methods()->length(); i++) {
225     Method* m = ik->methods()->at(i);
226     BytecodeStream bcs(methodHandle(THREAD, m));
227     while (!bcs.is_last_bytecode()) {
228       bcs.next();
229       Bytecodes::Code raw_bc = bcs.raw_code();
230       switch (raw_bc) {
231       case Bytecodes::_getstatic:
232       case Bytecodes::_putstatic:
233         maybe_resolve_fmi_ref(ik, m, raw_bc, bcs.get_index_u2(), preresolve_list, THREAD);
234         if (HAS_PENDING_EXCEPTION) {
235           CLEAR_PENDING_EXCEPTION; // just ignore
236         }
237         break;
238       case Bytecodes::_getfield:
239       // no-fast bytecode
240       case Bytecodes::_nofast_getfield:
241       // fast bytecodes
242       case Bytecodes::_fast_agetfield:
243       case Bytecodes::_fast_bgetfield:
244       case Bytecodes::_fast_cgetfield:
245       case Bytecodes::_fast_dgetfield:
246       case Bytecodes::_fast_fgetfield:
247       case Bytecodes::_fast_igetfield:
248       case Bytecodes::_fast_lgetfield:
249       case Bytecodes::_fast_sgetfield:
250         raw_bc = Bytecodes::_getfield;
251         maybe_resolve_fmi_ref(ik, m, raw_bc, bcs.get_index_u2(), preresolve_list, THREAD);
252         if (HAS_PENDING_EXCEPTION) {
253           CLEAR_PENDING_EXCEPTION; // just ignore
254         }
255         break;
256 
257       case Bytecodes::_putfield:
258       // no-fast bytecode
259       case Bytecodes::_nofast_putfield:
260       // fast bytecodes
261       case Bytecodes::_fast_aputfield:
262       case Bytecodes::_fast_bputfield:
263       case Bytecodes::_fast_zputfield:
264       case Bytecodes::_fast_cputfield:
265       case Bytecodes::_fast_dputfield:
266       case Bytecodes::_fast_fputfield:
267       case Bytecodes::_fast_iputfield:
268       case Bytecodes::_fast_lputfield:
269       case Bytecodes::_fast_sputfield:
270         raw_bc = Bytecodes::_putfield;
271         maybe_resolve_fmi_ref(ik, m, raw_bc, bcs.get_index_u2(), preresolve_list, THREAD);
272         if (HAS_PENDING_EXCEPTION) {
273           CLEAR_PENDING_EXCEPTION; // just ignore
274         }
275         break;
276       case Bytecodes::_invokehandle:
277       case Bytecodes::_invokespecial:
278       case Bytecodes::_invokevirtual:
279       case Bytecodes::_invokeinterface:
280       case Bytecodes::_invokestatic:
281         maybe_resolve_fmi_ref(ik, m, raw_bc, bcs.get_index_u2(), preresolve_list, THREAD);
282         if (HAS_PENDING_EXCEPTION) {
283           CLEAR_PENDING_EXCEPTION; // just ignore
284         }
285         break;
286       default:
287         break;
288       }
289     }
290   }
291 }
292 
293 void AOTConstantPoolResolver::maybe_resolve_fmi_ref(InstanceKlass* ik, Method* m, Bytecodes::Code bc, int raw_index,
294                                            GrowableArray<bool>* preresolve_list, TRAPS) {
295   methodHandle mh(THREAD, m);
296   constantPoolHandle cp(THREAD, ik->constants());
297   HandleMark hm(THREAD);
298   int cp_index = cp->to_cp_index(raw_index, bc);
299 
300   if (cp->is_resolved(raw_index, bc)) {
301     return;
302   }
303 
304   if (preresolve_list != nullptr && preresolve_list->at(cp_index) == false) {
305     // This field wasn't resolved during the trial run. Don't attempt to resolve it. Otherwise
306     // the compiler may generate less efficient code.
307     return;
308   }
309 
310   int klass_cp_index = cp->uncached_klass_ref_index_at(cp_index);
311   if (find_loaded_class(THREAD, cp(), klass_cp_index) == nullptr) {
312     // Do not resolve any field/methods from a class that has not been loaded yet.
313     return;
314   }
315 
316   Klass* resolved_klass = cp->klass_ref_at(raw_index, bc, CHECK);
317   const char* is_static = "";
318 
319   switch (bc) {
320   case Bytecodes::_getstatic:
321   case Bytecodes::_putstatic:
322     if (!VM_Version::supports_fast_class_init_checks()) {
323       return; // Do not resolve since interpreter lacks fast clinit barriers support
324     }
325     InterpreterRuntime::resolve_get_put(bc, raw_index, mh, cp, ClassInitMode::dont_init, CHECK);
326     is_static = " *** static";
327     break;
328 
329   case Bytecodes::_getfield:
330   case Bytecodes::_putfield:
331     InterpreterRuntime::resolve_get_put(bc, raw_index, mh, cp, ClassInitMode::dont_init, CHECK);
332     break;
333 
334   case Bytecodes::_invokestatic:
335     if (!VM_Version::supports_fast_class_init_checks()) {
336       return; // Do not resolve since interpreter lacks fast clinit barriers support
337     }
338     InterpreterRuntime::cds_resolve_invoke(bc, raw_index, cp, CHECK);
339     is_static = " *** static";
340     break;
341 
342   case Bytecodes::_invokevirtual:
343   case Bytecodes::_invokespecial:
344   case Bytecodes::_invokeinterface:
345     InterpreterRuntime::cds_resolve_invoke(bc, raw_index, cp, CHECK);
346     break;
347 
348   case Bytecodes::_invokehandle:
349     InterpreterRuntime::cds_resolve_invokehandle(raw_index, cp, CHECK);
350     break;
351 
352   default:
353     ShouldNotReachHere();
354   }
355 
356   if (log_is_enabled(Trace, aot, resolve)) {
357     ResourceMark rm(THREAD);
358     bool resolved = cp->is_resolved(raw_index, bc);
359     Symbol* name = cp->name_ref_at(raw_index, bc);
360     Symbol* signature = cp->signature_ref_at(raw_index, bc);
361     log_trace(aot, resolve)("%s %s [%3d] %s -> %s.%s:%s%s",
362                             (resolved ? "Resolved" : "Failed to resolve"),
363                             Bytecodes::name(bc), cp_index, ik->external_name(),
364                             resolved_klass->external_name(),
365                             name->as_C_string(), signature->as_C_string(), is_static);
366   }
367 }
368 
369 void AOTConstantPoolResolver::preresolve_indy_cp_entries(JavaThread* current, InstanceKlass* ik, GrowableArray<bool>* preresolve_list) {
370   JavaThread* THREAD = current;
371   constantPoolHandle cp(THREAD, ik->constants());
372   if (!CDSConfig::is_dumping_invokedynamic() || cp->cache() == nullptr) {
373     return;
374   }
375 
376   assert(preresolve_list != nullptr, "preresolve_indy_cp_entries() should not be called for "
377          "regenerated LambdaForm Invoker classes, which should not have indys anyway.");
378 
379   Array<ResolvedIndyEntry>* indy_entries = cp->cache()->resolved_indy_entries();
380   for (int i = 0; i < indy_entries->length(); i++) {
381     ResolvedIndyEntry* rie = indy_entries->adr_at(i);
382     int cp_index = rie->constant_pool_index();
383     if (preresolve_list->at(cp_index) == true) {
384       if (!rie->is_resolved() && is_indy_resolution_deterministic(cp(), cp_index)) {
385         InterpreterRuntime::cds_resolve_invokedynamic(i, cp, THREAD);
386         if (HAS_PENDING_EXCEPTION) {
387           CLEAR_PENDING_EXCEPTION; // just ignore
388         }
389       }
390       if (log_is_enabled(Trace, aot, resolve)) {
391         ResourceMark rm(THREAD);
392         log_trace(aot, resolve)("%s indy   [%3d] %s",
393                                 rie->is_resolved() ? "Resolved" : "Failed to resolve",
394                                 cp_index, ik->external_name());
395       }
396     }
397   }
398 }
399 
400 // Check the MethodType signatures used by parameters to the indy BSMs. Make sure we don't
401 // use types that have been excluded, or else we might end up creating MethodTypes that cannot be stored
402 // in the AOT cache.
403 bool AOTConstantPoolResolver::check_methodtype_signature(ConstantPool* cp, Symbol* sig, Klass** return_type_ret) {
404   ResourceMark rm;
405   for (SignatureStream ss(sig); !ss.is_done(); ss.next()) {
406     if (ss.is_reference()) {
407       Symbol* type = ss.as_symbol();
408       Klass* k = find_loaded_class(Thread::current(), cp->pool_holder()->class_loader(), type);
409       if (k == nullptr) {
410         return false;
411       }
412 
413       if (SystemDictionaryShared::should_be_excluded(k)) {
414         if (log_is_enabled(Warning, aot, resolve)) {
415           ResourceMark rm;
416           log_warning(aot, resolve)("Cannot aot-resolve Lambda proxy because %s is excluded", k->external_name());
417         }
418         return false;
419       }
420 
421       if (ss.at_return_type() && return_type_ret != nullptr) {
422         *return_type_ret = k;
423       }
424     }
425   }
426   return true;
427 }
428 
429 bool AOTConstantPoolResolver::check_lambda_metafactory_signature(ConstantPool* cp, Symbol* sig) {
430   Klass* k;
431   if (!check_methodtype_signature(cp, sig, &k)) {
432     return false;
433   }
434 
435   // <k> is the interface type implemented by the lambda proxy
436   if (!k->is_interface()) {
437     // cp->pool_holder() doesn't look like a valid class generated by javac
438     return false;
439   }
440 
441 
442   // The linked lambda callsite has an instance of the interface implemented by this lambda. If this
443   // interface requires its <clinit> to be executed, then we must delay the execution to the production run
444   // as <clinit> can have side effects ==> exclude such cases.
445   InstanceKlass* intf = InstanceKlass::cast(k);
446   bool exclude = intf->interface_needs_clinit_execution_as_super();
447   if (log_is_enabled(Debug, aot, resolve)) {
448     ResourceMark rm;
449     log_debug(aot, resolve)("%s aot-resolve Lambda proxy of interface type %s",
450                             exclude ? "Cannot" : "Can", k->external_name());
451   }
452   return !exclude;
453 }
454 
455 bool AOTConstantPoolResolver::check_lambda_metafactory_methodtype_arg(ConstantPool* cp, int bsms_attribute_index, int arg_i) {
456   int mt_index = cp->bsm_attribute_entry(bsms_attribute_index)->argument(arg_i);
457   if (!cp->tag_at(mt_index).is_method_type()) {
458     // malformed class?
459     return false;
460   }
461 
462   Symbol* sig = cp->method_type_signature_at(mt_index);
463   if (log_is_enabled(Debug, aot, resolve)) {
464     ResourceMark rm;
465     log_debug(aot, resolve)("Checking MethodType for LambdaMetafactory BSM arg %d: %s", arg_i, sig->as_C_string());
466   }
467 
468   return check_methodtype_signature(cp, sig);
469 }
470 
471 bool AOTConstantPoolResolver::check_lambda_metafactory_methodhandle_arg(ConstantPool* cp, int bsms_attribute_index, int arg_i) {
472   int mh_index = cp->bsm_attribute_entry(bsms_attribute_index)->argument(arg_i);
473   if (!cp->tag_at(mh_index).is_method_handle()) {
474     // malformed class?
475     return false;
476   }
477 
478   Symbol* sig = cp->method_handle_signature_ref_at(mh_index);
479   if (log_is_enabled(Debug, aot, resolve)) {
480     ResourceMark rm;
481     log_debug(aot, resolve)("Checking MethodType of MethodHandle for LambdaMetafactory BSM arg %d: %s", arg_i, sig->as_C_string());
482   }
483   return check_methodtype_signature(cp, sig);
484 }
485 
486 bool AOTConstantPoolResolver::is_indy_resolution_deterministic(ConstantPool* cp, int cp_index) {
487   assert(cp->tag_at(cp_index).is_invoke_dynamic(), "sanity");
488   if (!CDSConfig::is_dumping_invokedynamic()) {
489     return false;
490   }
491 
492   InstanceKlass* pool_holder = cp->pool_holder();
493   if (!SystemDictionaryShared::is_builtin(pool_holder)) {
494     return false;
495   }
496 
497   int bsm = cp->bootstrap_method_ref_index_at(cp_index);
498   int bsm_ref = cp->method_handle_index_at(bsm);
499   Symbol* bsm_name = cp->uncached_name_ref_at(bsm_ref);
500   Symbol* bsm_signature = cp->uncached_signature_ref_at(bsm_ref);
501   Symbol* bsm_klass = cp->klass_name_at(cp->uncached_klass_ref_index_at(bsm_ref));
502 
503   // We currently support only StringConcatFactory::makeConcatWithConstants() and LambdaMetafactory::metafactory()
504   // We should mark the allowed BSMs in the JDK code using a private annotation.
505   // See notes on RFE JDK-8342481.
506 
507   if (bsm_klass->equals("java/lang/invoke/StringConcatFactory") &&
508       bsm_name->equals("makeConcatWithConstants") &&
509       bsm_signature->equals("(Ljava/lang/invoke/MethodHandles$Lookup;"
510                              "Ljava/lang/String;"
511                              "Ljava/lang/invoke/MethodType;"
512                              "Ljava/lang/String;"
513                              "[Ljava/lang/Object;"
514                             ")Ljava/lang/invoke/CallSite;")) {
515     Symbol* factory_type_sig = cp->uncached_signature_ref_at(cp_index);
516     if (log_is_enabled(Debug, aot, resolve)) {
517       ResourceMark rm;
518       log_debug(aot, resolve)("Checking StringConcatFactory callsite signature [%d]: %s", cp_index, factory_type_sig->as_C_string());
519     }
520 
521     Klass* k;
522     if (!check_methodtype_signature(cp, factory_type_sig, &k)) {
523       return false;
524     }
525     if (k != vmClasses::String_klass()) {
526       // bad class file?
527       return false;
528     }
529 
530     return true;
531   }
532 
533   if (bsm_klass->equals("java/lang/invoke/LambdaMetafactory") &&
534       bsm_name->equals("metafactory") &&
535       bsm_signature->equals("(Ljava/lang/invoke/MethodHandles$Lookup;"
536                              "Ljava/lang/String;"
537                              "Ljava/lang/invoke/MethodType;"
538                              "Ljava/lang/invoke/MethodType;"
539                              "Ljava/lang/invoke/MethodHandle;"
540                              "Ljava/lang/invoke/MethodType;"
541                             ")Ljava/lang/invoke/CallSite;")) {
542     /*
543      * An indy callsite is associated with the following MethodType and MethodHandles:
544      *
545      * https://github.com/openjdk/jdk/blob/580eb62dc097efeb51c76b095c1404106859b673/src/java.base/share/classes/java/lang/invoke/LambdaMetafactory.java#L293-L309
546      *
547      * MethodType factoryType         The expected signature of the {@code CallSite}.  The
548      *                                parameter types represent the types of capture variables;
549      *                                the return type is the interface to implement.   When
550      *                                used with {@code invokedynamic}, this is provided by
551      *                                the {@code NameAndType} of the {@code InvokeDynamic}
552      *
553      * MethodType interfaceMethodType Signature and return type of method to be
554      *                                implemented by the function object.
555      *
556      * MethodHandle implementation    A direct method handle describing the implementation
557      *                                method which should be called (with suitable adaptation
558      *                                of argument types and return types, and with captured
559      *                                arguments prepended to the invocation arguments) at
560      *                                invocation time.
561      *
562      * MethodType dynamicMethodType   The signature and return type that should
563      *                                be enforced dynamically at invocation time.
564      *                                In simple use cases this is the same as
565      *                                {@code interfaceMethodType}.
566      */
567     Symbol* factory_type_sig = cp->uncached_signature_ref_at(cp_index);
568     if (log_is_enabled(Debug, aot, resolve)) {
569       ResourceMark rm;
570       log_debug(aot, resolve)("Checking lambda callsite signature [%d]: %s", cp_index, factory_type_sig->as_C_string());
571     }
572 
573     if (!check_lambda_metafactory_signature(cp, factory_type_sig)) {
574       return false;
575     }
576 
577     int bsms_attribute_index = cp->bootstrap_methods_attribute_index(cp_index);
578     int arg_count = cp->bsm_attribute_entry(bsms_attribute_index)->argument_count();
579     if (arg_count != 3) {
580       // Malformed class?
581       return false;
582     }
583 
584     // interfaceMethodType
585     if (!check_lambda_metafactory_methodtype_arg(cp, bsms_attribute_index, 0)) {
586       return false;
587     }
588 
589     // implementation
590     if (!check_lambda_metafactory_methodhandle_arg(cp, bsms_attribute_index, 1)) {
591       return false;
592     }
593 
594     // dynamicMethodType
595     if (!check_lambda_metafactory_methodtype_arg(cp, bsms_attribute_index, 2)) {
596       return false;
597     }
598 
599     return true;
600   }
601 
602   return false;
603 }
604 #ifdef ASSERT
605 bool AOTConstantPoolResolver::is_in_archivebuilder_buffer(address p) {
606   if (!Thread::current()->is_VM_thread() || ArchiveBuilder::current() == nullptr) {
607     return false;
608   } else {
609     return ArchiveBuilder::current()->is_in_buffer_space(p);
610   }
611 }
612 #endif