-/********************* 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)
- pthread_mutex_lock(&compiler_mutex);
-#endif
-
- /* avoid recursive calls */
- if (loader_load_running)
- return class_new(topname);
-
- loader_load_running++;
-
- intsDisable();
-
- if (getloadingtime)
- starttime = getcputime();
-
- top = class_new(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...");
-
- /* XXX 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)
- throw_linkageerror_message(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)");
- throw_noclassdeffounderror_message(top->name);
- top = NULL;
-
- } else if (!top->linked) {
- if (linkverbose)
- dolog("Failed to link class (former call)");
- throw_linkageerror_message(top->name);
- top = NULL;
- }
- }
-
- intsRestore();
-
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- pthread_mutex_unlock(&compiler_mutex);
-#endif
-
- /* XXX 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;
-}
-
-