-/********************* Function: loader_load ***********************************
-
- Loads and links the class desired class and each class and interface
- referenced by it.
- Returns: a pointer to this class
-
-*******************************************************************************/
-
-static int loader_load_running = 0;
-
-classinfo *loader_load(utf *topname)
-{
- classinfo *top;
- classinfo *c;
- s8 starttime = 0;
- s8 stoptime = 0;
- classinfo *notlinkable;
-
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- compiler_lock();
- tables_lock();
-#endif
-
- /* avoid recursive calls */
- if (loader_load_running) {
- tables_unlock();
- compiler_unlock();
- return class_new_int(topname);
- }
-
- loader_load_running++;
-
-#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
- intsDisable();
-#endif
-
- if (getloadingtime)
- starttime = getcputime();
-
- top = class_new_int(topname);
-
- /* load classes */
- while ((c = list_first(&unloadedclasses))) {
- if (!class_load(c)) {
- if (linkverbose)
- dolog("Failed to load class");
- list_remove(&unloadedclasses, c);
- top = NULL;
- }
- }
-
- /* link classes */
- if (linkverbose)
- dolog("Linking...");
-
- /* Added a hack to break infinite linking loops. A better
- * linking algorithm would be nice. -Edwin */
- notlinkable = NULL;
- while ((c = list_first(&unlinkedclasses))) {
- class_link(c);
- if (!c->linked) {
- if (!notlinkable)
- notlinkable = c;
- else if (notlinkable == c) {
- /* We tried to link this class for the second time and
- * no other classes were linked in between, so we are
- * caught in a loop.
- */
- if (linkverbose)
- dolog("Cannot resolve linking dependencies");
- top = NULL;
-
- if (!*exceptionptr)
- *exceptionptr = new_exception_utfmessage(string_java_lang_LinkageError,
- c->name);
- break;
- }
-
- } else
- notlinkable = NULL;
- }
- if (linkverbose)
- dolog("Linking done.");
-
- if (loader_inited)
- loader_compute_subclasses();
-
- /* measure time */
- if (getloadingtime) {
- stoptime = getcputime();
- loadingtime += (stoptime - starttime);
- }
-
-
- loader_load_running--;
-
- /* check if a former loader_load call tried to load/link the class and
- failed. This is needed because the class didn't appear in the
- undloadclasses or unlinkedclasses list during this class. */
- if (top) {
- if (!top->loaded) {
- if (linkverbose)
- dolog("Failed to load class (former call)");
-
- new_exception_utfmessage(string_java_lang_NoClassDefFoundError,
- top->name);
- top = NULL;
-
- } else if (!top->linked) {
- if (linkverbose)
- dolog("Failed to link class (former call)");
-
- new_exception_utfmessage(string_java_lang_LinkageError,
- top->name);
- top = NULL;
- }
- }
-
-#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
- intsRestore();
-#endif
-
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- tables_unlock();
- compiler_unlock();
-#endif
-
- /* DEBUG */ /*if (linkverbose && !top) dolog("returning NULL from loader_load");*/
-
- return top;
-}
-
-
-/****************** Function: loader_load_sysclass ****************************
-
- Loads and links the class desired class and each class and interface
- referenced by it.
-
- The pointer to the classinfo is stored in *top if top != NULL.
- The pointer is also returned.
-
- If the class could not be loaded the function aborts with an error.
-
-*******************************************************************************/
-
-classinfo *loader_load_sysclass(classinfo **top, utf *topname)
-{
- classinfo *cls;
-
- if ((cls = loader_load(topname)) == NULL) {
- log_plain("Could not load important system class: ");
- log_plain_utf(topname);
- log_nl();
- panic("Could not load important system class");
- }
-
- if (top) *top = cls;
-
- return cls;
-}
-
-