+// Check loading constraints for method.
+void
+_Jv_Linker::check_loading_constraints (_Jv_Method *method, jclass self_class,
+ jclass other_class)
+{
+ JArray<jclass> *klass_args;
+ jclass klass_return;
+
+ _Jv_GetTypesFromSignature (method, self_class, &klass_args, &klass_return);
+ jclass *klass_arg = elements (klass_args);
+ java::lang::ClassLoader *found_loader = other_class->loader;
+
+ _Jv_CheckOrCreateLoadingConstraint (klass_return, found_loader);
+ for (int i = 0; i < klass_args->length; i++)
+ _Jv_CheckOrCreateLoadingConstraint (*(klass_arg++), found_loader);
+}
+
+_Jv_Method *
+_Jv_Linker::resolve_method_entry (jclass klass, jclass &found_class,
+ int class_index, int name_and_type_index,
+ bool init, bool is_iface)
+{
+ _Jv_Constants *pool = &klass->constants;
+ jclass owner = resolve_pool_entry (klass, class_index).clazz;
+
+ if (init && owner != klass)
+ _Jv_InitClass (owner);
+
+ _Jv_ushort name_index, type_index;
+ _Jv_loadIndexes (&pool->data[name_and_type_index],
+ name_index,
+ type_index);
+
+ _Jv_Utf8Const *method_name = pool->data[name_index].utf8;
+ _Jv_Utf8Const *method_signature = pool->data[type_index].utf8;
+
+ _Jv_Method *the_method = 0;
+ found_class = 0;
+
+ // We're going to cache a pointer to the _Jv_Method object
+ // when we find it. So, to ensure this doesn't get moved from
+ // beneath us, we first put all the needed Miranda methods
+ // into the target class.
+ wait_for_state (klass, JV_STATE_LOADED);
+
+ // First search the class itself.
+ the_method = search_method_in_class (owner, klass,
+ method_name, method_signature);
+
+ if (the_method != 0)
+ {
+ found_class = owner;
+ goto end_of_method_search;
+ }
+
+ // If we are resolving an interface method, search the
+ // interface's superinterfaces (A superinterface is not an
+ // interface's superclass - a superinterface is implemented by
+ // the interface).
+ if (is_iface)
+ {
+ _Jv_ifaces ifaces;
+ ifaces.count = 0;
+ ifaces.len = 4;
+ ifaces.list = (jclass *) _Jv_Malloc (ifaces.len
+ * sizeof (jclass *));
+
+ get_interfaces (owner, &ifaces);
+
+ for (int i = 0; i < ifaces.count; i++)
+ {
+ jclass cls = ifaces.list[i];
+ the_method = search_method_in_class (cls, klass, method_name,
+ method_signature);
+ if (the_method != 0)
+ {
+ found_class = cls;
+ break;
+ }
+ }
+
+ _Jv_Free (ifaces.list);
+
+ if (the_method != 0)
+ goto end_of_method_search;
+ }
+
+ // Finally, search superclasses.
+ the_method = (search_method_in_superclasses
+ (owner->getSuperclass (), klass, method_name,
+ method_signature, &found_class));
+
+
+ end_of_method_search:
+ if (the_method == 0)
+ {
+ java::lang::StringBuffer *sb = new java::lang::StringBuffer();
+ sb->append(JvNewStringLatin1("method "));
+ sb->append(owner->getName());
+ sb->append(JvNewStringLatin1("."));
+ sb->append(_Jv_NewStringUTF(method_name->chars()));
+ sb->append(JvNewStringLatin1(" with signature "));
+ sb->append(_Jv_NewStringUTF(method_signature->chars()));
+ sb->append(JvNewStringLatin1(" was not found."));
+ throw new java::lang::NoSuchMethodError (sb->toString());
+ }
+
+ // if (found_class->loader != klass->loader), then we must actually
+ // check that the types of arguments correspond. JVMS 5.4.3.3.
+ if (found_class->loader != klass->loader)
+ check_loading_constraints (the_method, klass, found_class);
+
+ return the_method;
+}
+
+_Jv_Mutex_t _Jv_Linker::resolve_mutex;
+
+void
+_Jv_Linker::init (void)
+{
+ _Jv_MutexInit (&_Jv_Linker::resolve_mutex);
+}
+
+// Locking in resolve_pool_entry is somewhat subtle. Constant
+// resolution is idempotent, so it doesn't matter if two threads
+// resolve the same entry. However, it is important that we always
+// write the resolved flag and the data together, atomically. It is
+// also important that we read them atomically.