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