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