1 /* src/vm/loader.c - class loader functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
34 #include "mm/memory.h"
36 #include "native/llni.h"
38 #include "threads/lock-common.h"
40 #include "toolbox/hashtable.h"
41 #include "toolbox/logging.h"
43 #include "vm/builtin.h"
44 #include "vm/classcache.h"
45 #include "vm/exceptions.hpp"
47 #include "vm/global.h"
48 #include "vm/globals.hpp"
49 #include "vm/linker.h"
50 #include "vm/loader.h"
51 #include "vm/method.h"
52 #include "vm/options.h"
53 #include "vm/package.hpp"
54 #include "vm/primitive.hpp"
55 #include "vm/resolve.h"
56 #include "vm/rt-timing.h"
57 #include "vm/string.hpp"
62 #if defined(ENABLE_JAVASE)
63 # include "vm/annotation.h"
64 # include "vm/stackmap.h"
67 #if defined(ENABLE_STATISTICS)
68 # include "vm/statistics.h"
71 #if defined(ENABLE_ZLIB)
75 #if defined(ENABLE_JVMTI)
76 # include "native/jvmti/cacaodbg.h"
80 /* global variables ***********************************************************/
82 static hashtable *hashtable_classloader;
85 /* loader_preinit **************************************************************
87 Initializes the classpath list and loads classes required for the
90 NOTE: Exceptions thrown during VM initialization are caught in the
91 exception functions themselves.
93 *******************************************************************************/
95 void loader_preinit(void)
97 #if defined(ENABLE_THREADS)
98 list_classpath_entry *lce;
101 TRACESUBSYSTEMINITIALIZATION("loader_preinit");
103 #if defined(ENABLE_THREADS)
104 /* Initialize the monitor pointer for zip/jar file locking. */
106 for (lce = list_first(list_classpath_entries); lce != NULL;
107 lce = list_next(list_classpath_entries, lce)) {
108 if (lce->type == CLASSPATH_ARCHIVE)
109 LOCK_INIT_OBJECT_LOCK(lce);
113 /* initialize classloader hashtable, 10 entries should be enough */
115 hashtable_classloader = NEW(hashtable);
116 hashtable_create(hashtable_classloader, 10);
118 /* Load the most basic classes. */
120 assert(VM_is_initializing() == true);
122 class_java_lang_Object = load_class_bootstrap(utf_java_lang_Object);
124 #if defined(ENABLE_JAVASE)
125 class_java_lang_Cloneable = load_class_bootstrap(utf_java_lang_Cloneable);
126 class_java_io_Serializable = load_class_bootstrap(utf_java_io_Serializable);
131 /* loader_init *****************************************************************
133 Loads all classes required in the VM.
135 NOTE: Exceptions thrown during VM initialization are caught in the
136 exception functions themselves.
138 *******************************************************************************/
140 void loader_init(void)
142 TRACESUBSYSTEMINITIALIZATION("loader_init");
144 /* Load primitive-type wrapping classes. */
146 assert(VM_is_initializing() == true);
148 #if defined(ENABLE_JAVASE)
149 class_java_lang_Void = load_class_bootstrap(utf_java_lang_Void);
152 class_java_lang_Boolean = load_class_bootstrap(utf_java_lang_Boolean);
153 class_java_lang_Byte = load_class_bootstrap(utf_java_lang_Byte);
154 class_java_lang_Character = load_class_bootstrap(utf_java_lang_Character);
155 class_java_lang_Short = load_class_bootstrap(utf_java_lang_Short);
156 class_java_lang_Integer = load_class_bootstrap(utf_java_lang_Integer);
157 class_java_lang_Long = load_class_bootstrap(utf_java_lang_Long);
158 class_java_lang_Float = load_class_bootstrap(utf_java_lang_Float);
159 class_java_lang_Double = load_class_bootstrap(utf_java_lang_Double);
161 /* Load important system classes. */
163 class_java_lang_Class = load_class_bootstrap(utf_java_lang_Class);
164 class_java_lang_String = load_class_bootstrap(utf_java_lang_String);
166 #if defined(ENABLE_JAVASE)
167 class_java_lang_ClassLoader =
168 load_class_bootstrap(utf_java_lang_ClassLoader);
170 class_java_lang_SecurityManager =
171 load_class_bootstrap(utf_java_lang_SecurityManager);
174 class_java_lang_System =
175 load_class_bootstrap(utf_new_char("java/lang/System"));
177 class_java_lang_Thread =
178 load_class_bootstrap(utf_new_char("java/lang/Thread"));
180 #if defined(ENABLE_JAVASE)
181 class_java_lang_ThreadGroup =
182 load_class_bootstrap(utf_java_lang_ThreadGroup);
185 class_java_lang_Throwable = load_class_bootstrap(utf_java_lang_Throwable);
187 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
188 class_java_lang_VMSystem =
189 load_class_bootstrap(utf_new_char("java/lang/VMSystem"));
191 class_java_lang_VMThread =
192 load_class_bootstrap(utf_new_char("java/lang/VMThread"));
194 class_java_lang_VMThrowable =
195 load_class_bootstrap(utf_new_char("java/lang/VMThrowable"));
198 /* Important system exceptions. */
200 class_java_lang_Exception = load_class_bootstrap(utf_java_lang_Exception);
202 class_java_lang_ClassNotFoundException =
203 load_class_bootstrap(utf_java_lang_ClassNotFoundException);
205 class_java_lang_RuntimeException =
206 load_class_bootstrap(utf_java_lang_RuntimeException);
208 /* Some classes which may be used often. */
210 #if defined(ENABLE_JAVASE)
211 class_java_lang_StackTraceElement = load_class_bootstrap(utf_java_lang_StackTraceElement);
213 class_java_lang_reflect_Constructor = load_class_bootstrap(utf_java_lang_reflect_Constructor);
214 class_java_lang_reflect_Field = load_class_bootstrap(utf_java_lang_reflect_Field);
215 class_java_lang_reflect_Method = load_class_bootstrap(utf_java_lang_reflect_Method);
217 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
218 class_java_lang_reflect_VMConstructor = load_class_bootstrap(utf_java_lang_reflect_VMConstructor);
219 class_java_lang_reflect_VMField = load_class_bootstrap(utf_java_lang_reflect_VMField);
220 class_java_lang_reflect_VMMethod = load_class_bootstrap(utf_java_lang_reflect_VMMethod);
223 class_java_security_PrivilegedAction = load_class_bootstrap(utf_new_char("java/security/PrivilegedAction"));
225 class_java_util_HashMap = load_class_bootstrap(utf_new_char("java/util/HashMap"));
226 class_java_util_Vector = load_class_bootstrap(utf_java_util_Vector);
228 # if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
229 class_sun_misc_Signal = load_class_bootstrap(utf_new_char("sun/misc/Signal"));
230 class_sun_reflect_MagicAccessorImpl = load_class_bootstrap(utf_new_char("sun/reflect/MagicAccessorImpl"));
233 arrayclass_java_lang_Object =
234 load_class_bootstrap(utf_new_char("[Ljava/lang/Object;"));
236 # if defined(ENABLE_ANNOTATIONS)
237 /* needed by annotation support */
238 class_sun_reflect_ConstantPool =
239 load_class_bootstrap(utf_new_char("sun/reflect/ConstantPool"));
241 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
242 /* needed by GNU Classpaths annotation support */
243 class_sun_reflect_annotation_AnnotationParser =
244 load_class_bootstrap(utf_new_char("sun/reflect/annotation/AnnotationParser"));
251 /* loader_hashtable_classloader_add ********************************************
253 Adds an entry to the classloader hashtable.
255 REMEMBER: Also use this to register native loaders!
257 *******************************************************************************/
259 classloader_t *loader_hashtable_classloader_add(java_handle_t *cl)
261 hashtable_classloader_entry *cle;
268 LOCK_MONITOR_ENTER(hashtable_classloader->header);
272 /* key for entry is the hashcode of the classloader;
273 aligned to 16-byte boundaries */
275 key = heap_hashcode(LLNI_DIRECT(cl)) >> 4;
276 slot = key & (hashtable_classloader->size - 1);
277 cle = hashtable_classloader->ptr[slot];
279 /* search hashchain for existing entry */
282 if (cle->object == LLNI_DIRECT(cl))
290 /* if no classloader was found, we create a new entry here */
293 cle = NEW(hashtable_classloader_entry);
295 #if defined(ENABLE_GC_CACAO)
296 /* register the classloader object with the GC */
298 gc_reference_register(&(cle->object), GC_REFTYPE_CLASSLOADER);
303 cle->object = LLNI_DIRECT(cl);
307 /*#define LOADER_DEBUG_CLASSLOADER*/
308 #ifdef LOADER_DEBUG_CLASSLOADER
309 printf("CLASSLOADER: adding new classloader entry %p for %p: ", cle, cl);
310 class_print(LLNI_vftbl_direct(cl)->class);
315 /* insert entry into hashtable */
317 cle->hashlink = hashtable_classloader->ptr[slot];
318 hashtable_classloader->ptr[slot] = cle;
320 /* update number of entries */
322 hashtable_classloader->entries++;
326 LOCK_MONITOR_EXIT(hashtable_classloader->header);
328 #if defined(ENABLE_HANDLES)
336 /* loader_hashtable_classloader_find *******************************************
338 Find an entry in the classloader hashtable.
340 *******************************************************************************/
342 classloader_t *loader_hashtable_classloader_find(java_handle_t *cl)
344 hashtable_classloader_entry *cle;
353 /* key for entry is the hashcode of the classloader;
354 aligned to 16-byte boundaries */
356 key = heap_hashcode(LLNI_DIRECT(cl)) >> 4;
357 slot = key & (hashtable_classloader->size - 1);
358 cle = hashtable_classloader->ptr[slot];
360 /* search hashchain for existing entry */
363 if (cle->object == LLNI_DIRECT(cl))
369 #ifdef LOADER_DEBUG_CLASSLOADER
371 printf("CLASSLOADER: unable to find classloader entry for %p: ", cl);
372 class_print(LLNI_vftbl_direct(cl)->class);
380 #if defined(ENABLE_HANDLES)
388 /* loader_load_all_classes *****************************************************
390 Loads all classes specified in the BOOTCLASSPATH.
392 *******************************************************************************/
394 void loader_load_all_classes(void)
396 list_classpath_entry *lce;
397 #if defined(ENABLE_ZLIB)
400 hashtable_zipfile_entry *htzfe;
404 for (lce = list_first(list_classpath_entries); lce != NULL;
405 lce = list_next(list_classpath_entries, lce)) {
406 #if defined(ENABLE_ZLIB)
407 if (lce->type == CLASSPATH_ARCHIVE) {
408 /* get the classes hashtable */
412 for (slot = 0; slot < ht->size; slot++) {
413 htzfe = (hashtable_zipfile_entry *) ht->ptr[slot];
415 for (; htzfe; htzfe = htzfe->hashlink) {
418 /* skip all entries in META-INF and .properties,
421 if (!strncmp(u->text, "META-INF", strlen("META-INF")) ||
422 strstr(u->text, ".properties") ||
423 strstr(u->text, ".png"))
426 /* load class from bootstrap classloader */
428 if (!load_class_bootstrap(u)) {
429 fprintf(stderr, "Error loading: ");
430 utf_fprint_printable_ascii_classname(stderr, u);
431 fprintf(stderr, "\n");
434 /* print out exception and cause */
436 exceptions_print_current_exception();
444 #if defined(ENABLE_ZLIB)
451 /* loader_skip_attribute_body **************************************************
453 Skips an attribute the attribute_name_index has already been read.
456 u2 attribute_name_index;
458 u1 info[attribute_length];
461 *******************************************************************************/
463 bool loader_skip_attribute_body(classbuffer *cb)
467 if (!suck_check_classbuffer_size(cb, 4))
470 attribute_length = suck_u4(cb);
472 if (!suck_check_classbuffer_size(cb, attribute_length))
475 suck_skip_nbytes(cb, attribute_length);
481 /* load_constantpool ***********************************************************
483 Loads the constantpool of a class, the entries are transformed into
484 a simpler format by resolving references (a detailed overview of
485 the compact structures can be found in global.h).
487 *******************************************************************************/
489 static bool load_constantpool(classbuffer *cb, descriptor_pool *descpool)
492 /* The following structures are used to save information which cannot be
493 processed during the first pass. After the complete constantpool has
494 been traversed the references can be resolved.
495 (only in specific order) */
497 /* CONSTANT_Class entries */
498 typedef struct forward_class {
499 struct forward_class *next;
504 /* CONSTANT_String */
505 typedef struct forward_string {
506 struct forward_string *next;
511 /* CONSTANT_NameAndType */
512 typedef struct forward_nameandtype {
513 struct forward_nameandtype *next;
517 } forward_nameandtype;
519 /* CONSTANT_Fieldref, CONSTANT_Methodref or CONSTANT_InterfaceMethodref */
520 typedef struct forward_fieldmethint {
521 struct forward_fieldmethint *next;
525 u2 nameandtype_index;
526 } forward_fieldmethint;
532 forward_class *forward_classes = NULL;
533 forward_string *forward_strings = NULL;
534 forward_nameandtype *forward_nameandtypes = NULL;
535 forward_fieldmethint *forward_fieldmethints = NULL;
539 forward_nameandtype *nfn;
540 forward_fieldmethint *nff;
548 /* number of entries in the constant_pool table plus one */
549 if (!suck_check_classbuffer_size(cb, 2))
552 cpcount = c->cpcount = suck_u2(cb);
554 /* allocate memory */
555 cptags = c->cptags = MNEW(u1, cpcount);
556 cpinfos = c->cpinfos = MNEW(void*, cpcount);
559 exceptions_throw_classformaterror(c, "Illegal constant pool size");
563 #if defined(ENABLE_STATISTICS)
565 count_const_pool_len += (sizeof(u1) + sizeof(void*)) * cpcount;
568 /* initialize constantpool */
569 for (idx = 0; idx < cpcount; idx++) {
570 cptags[idx] = CONSTANT_UNUSED;
575 /******* first pass *******/
576 /* entries which cannot be resolved now are written into
577 temporary structures and traversed again later */
580 while (idx < cpcount) {
583 /* get constant type */
584 if (!suck_check_classbuffer_size(cb, 1))
591 nfc = DNEW(forward_class);
593 nfc->next = forward_classes;
594 forward_classes = nfc;
596 nfc->thisindex = idx;
597 /* reference to CONSTANT_NameAndType */
598 if (!suck_check_classbuffer_size(cb, 2))
601 nfc->name_index = suck_u2(cb);
606 case CONSTANT_String:
607 nfs = DNEW(forward_string);
609 nfs->next = forward_strings;
610 forward_strings = nfs;
612 nfs->thisindex = idx;
614 /* reference to CONSTANT_Utf8_info with string characters */
615 if (!suck_check_classbuffer_size(cb, 2))
618 nfs->string_index = suck_u2(cb);
623 case CONSTANT_NameAndType:
624 nfn = DNEW(forward_nameandtype);
626 nfn->next = forward_nameandtypes;
627 forward_nameandtypes = nfn;
629 nfn->thisindex = idx;
631 if (!suck_check_classbuffer_size(cb, 2 + 2))
634 /* reference to CONSTANT_Utf8_info containing simple name */
635 nfn->name_index = suck_u2(cb);
637 /* reference to CONSTANT_Utf8_info containing field or method
639 nfn->sig_index = suck_u2(cb);
644 case CONSTANT_Fieldref:
645 case CONSTANT_Methodref:
646 case CONSTANT_InterfaceMethodref:
647 nff = DNEW(forward_fieldmethint);
649 nff->next = forward_fieldmethints;
650 forward_fieldmethints = nff;
652 nff->thisindex = idx;
656 if (!suck_check_classbuffer_size(cb, 2 + 2))
659 /* class or interface type that contains the declaration of the
661 nff->class_index = suck_u2(cb);
663 /* name and descriptor of the field or method */
664 nff->nameandtype_index = suck_u2(cb);
669 case CONSTANT_Integer: {
670 constant_integer *ci = NEW(constant_integer);
672 #if defined(ENABLE_STATISTICS)
674 count_const_pool_len += sizeof(constant_integer);
677 if (!suck_check_classbuffer_size(cb, 4))
680 ci->value = suck_s4(cb);
681 cptags[idx] = CONSTANT_Integer;
688 case CONSTANT_Float: {
689 constant_float *cf = NEW(constant_float);
691 #if defined(ENABLE_STATISTICS)
693 count_const_pool_len += sizeof(constant_float);
696 if (!suck_check_classbuffer_size(cb, 4))
699 cf->value = suck_float(cb);
700 cptags[idx] = CONSTANT_Float;
707 case CONSTANT_Long: {
708 constant_long *cl = NEW(constant_long);
710 #if defined(ENABLE_STATISTICS)
712 count_const_pool_len += sizeof(constant_long);
715 if (!suck_check_classbuffer_size(cb, 8))
718 cl->value = suck_s8(cb);
719 cptags[idx] = CONSTANT_Long;
723 exceptions_throw_classformaterror(c, "Invalid constant pool entry");
729 case CONSTANT_Double: {
730 constant_double *cd = NEW(constant_double);
732 #if defined(ENABLE_STATISTICS)
734 count_const_pool_len += sizeof(constant_double);
737 if (!suck_check_classbuffer_size(cb, 8))
740 cd->value = suck_double(cb);
741 cptags[idx] = CONSTANT_Double;
745 exceptions_throw_classformaterror(c, "Invalid constant pool entry");
751 case CONSTANT_Utf8: {
754 /* number of bytes in the bytes array (not string-length) */
755 if (!suck_check_classbuffer_size(cb, 2))
758 length = suck_u2(cb);
759 cptags[idx] = CONSTANT_Utf8;
761 /* validate the string */
762 if (!suck_check_classbuffer_size(cb, length))
765 #ifdef ENABLE_VERIFIER
767 !is_valid_utf((char *) cb->pos, (char *) (cb->pos + length)))
769 exceptions_throw_classformaterror(c, "Invalid UTF-8 string");
772 #endif /* ENABLE_VERIFIER */
773 /* insert utf-string into the utf-symboltable */
774 cpinfos[idx] = utf_new((char *) cb->pos, length);
776 /* skip bytes of the string (buffer size check above) */
777 suck_skip_nbytes(cb, length);
783 exceptions_throw_classformaterror(c, "Illegal constant pool type");
789 /* resolve entries in temporary structures */
791 while (forward_classes) {
793 class_getconstant(c, forward_classes->name_index, CONSTANT_Utf8);
797 #ifdef ENABLE_VERIFIER
798 if (opt_verify && !is_valid_name_utf(name)) {
799 exceptions_throw_classformaterror(c, "Class reference with invalid name");
802 #endif /* ENABLE_VERIFIER */
804 /* add all class references to the descriptor_pool */
806 if (!descriptor_pool_add_class(descpool, name))
809 cptags[forward_classes->thisindex] = CONSTANT_Class;
811 /* the classref is created later */
812 cpinfos[forward_classes->thisindex] = name;
814 nfc = forward_classes;
815 forward_classes = forward_classes->next;
818 while (forward_strings) {
820 class_getconstant(c, forward_strings->string_index, CONSTANT_Utf8);
824 /* resolve utf-string */
825 cptags[forward_strings->thisindex] = CONSTANT_String;
826 cpinfos[forward_strings->thisindex] = text;
828 nfs = forward_strings;
829 forward_strings = forward_strings->next;
832 while (forward_nameandtypes) {
833 constant_nameandtype *cn = NEW(constant_nameandtype);
835 #if defined(ENABLE_STATISTICS)
837 count_const_pool_len += sizeof(constant_nameandtype);
840 /* resolve simple name and descriptor */
841 cn->name = class_getconstant(c,
842 forward_nameandtypes->name_index,
847 cn->descriptor = class_getconstant(c,
848 forward_nameandtypes->sig_index,
853 #ifdef ENABLE_VERIFIER
856 if (!is_valid_name_utf(cn->name)) {
857 exceptions_throw_classformaterror(c,
858 "Illegal Field name \"%s\"",
864 /* disallow referencing <clinit> among others */
865 if (cn->name->text[0] == '<' && cn->name != utf_init) {
866 exceptions_throw_classformaterror(c, "Illegal reference to special method");
870 #endif /* ENABLE_VERIFIER */
872 cptags[forward_nameandtypes->thisindex] = CONSTANT_NameAndType;
873 cpinfos[forward_nameandtypes->thisindex] = cn;
875 nfn = forward_nameandtypes;
876 forward_nameandtypes = forward_nameandtypes->next;
879 while (forward_fieldmethints) {
880 constant_nameandtype *nat;
881 constant_FMIref *fmi = NEW(constant_FMIref);
883 #if defined(ENABLE_STATISTICS)
885 count_const_pool_len += sizeof(constant_FMIref);
887 /* resolve simple name and descriptor */
889 nat = class_getconstant(c,
890 forward_fieldmethints->nameandtype_index,
891 CONSTANT_NameAndType);
895 /* add all descriptors in {Field,Method}ref to the descriptor_pool */
897 if (!descriptor_pool_add(descpool, nat->descriptor, NULL))
900 /* the classref is created later */
902 fmi->p.index = forward_fieldmethints->class_index;
903 fmi->name = nat->name;
904 fmi->descriptor = nat->descriptor;
906 cptags[forward_fieldmethints->thisindex] = forward_fieldmethints->tag;
907 cpinfos[forward_fieldmethints->thisindex] = fmi;
909 nff = forward_fieldmethints;
910 forward_fieldmethints = forward_fieldmethints->next;
913 /* everything was ok */
919 /* loader_load_attribute_signature *********************************************
921 Signature_attribute {
922 u2 attribute_name_index;
927 *******************************************************************************/
929 #if defined(ENABLE_JAVASE)
930 bool loader_load_attribute_signature(classbuffer *cb, utf **signature)
940 /* check remaining bytecode */
942 if (!suck_check_classbuffer_size(cb, 4 + 2))
945 /* check attribute length */
947 attribute_length = suck_u4(cb);
949 if (attribute_length != 2) {
950 exceptions_throw_classformaterror(c, "Wrong size for VALUE attribute");
954 if (*signature != NULL) {
955 exceptions_throw_classformaterror(c, "Multiple Signature attributes");
961 signature_index = suck_u2(cb);
963 if (!(*signature = class_getconstant(c, signature_index, CONSTANT_Utf8)))
968 #endif /* defined(ENABLE_JAVASE) */
971 /* load_class_from_sysloader ***************************************************
973 Load the class with the given name using the system class loader
976 name.............the classname
980 NULL if an exception has been thrown
982 *******************************************************************************/
984 classinfo *load_class_from_sysloader(utf *name)
991 assert(class_java_lang_Object);
992 assert(class_java_lang_ClassLoader);
993 assert(class_java_lang_ClassLoader->state & CLASS_LINKED);
995 m = class_resolveclassmethod(class_java_lang_ClassLoader,
996 utf_getSystemClassLoader,
997 utf_void__java_lang_ClassLoader,
998 class_java_lang_Object,
1004 clo = vm_call_method(m, NULL);
1009 cl = loader_hashtable_classloader_add(clo);
1011 c = load_class_from_classloader(name, cl);
1017 /* load_class_from_classloader *************************************************
1019 Load the class with the given name using the given user-defined class loader.
1022 name.............the classname
1023 cl...............user-defined class loader
1026 the loaded class, or
1027 NULL if an exception has been thrown
1029 *******************************************************************************/
1031 classinfo *load_class_from_classloader(utf *name, classloader_t *cl)
1036 java_handle_t *string;
1037 #if defined(ENABLE_RT_TIMING)
1038 struct timespec time_start, time_lookup, time_prepare, time_java,
1042 RT_TIMING_GET_TIME(time_start);
1046 /* lookup if this class has already been loaded */
1048 c = classcache_lookup(cl, name);
1050 RT_TIMING_GET_TIME(time_lookup);
1051 RT_TIMING_TIME_DIFF(time_start,time_lookup,RT_TIMING_LOAD_CL_LOOKUP);
1056 /* if other class loader than bootstrap, call it */
1064 namelen = name->blength;
1066 /* handle array classes */
1067 if (text[0] == '[') {
1073 /* check for cases like `[L;' or `[L[I;' or `[Ljava.lang.Object' */
1074 if (namelen < 4 || text[2] == '[' || text[namelen - 1] != ';') {
1075 exceptions_throw_classnotfoundexception(name);
1079 u = utf_new(text + 2, namelen - 3);
1081 if (!(comp = load_class_from_classloader(u, cl)))
1084 /* create the array class */
1086 c = class_array_of(comp, false);
1088 tmpc = classcache_store(cl, c, true);
1091 /* exception, free the loaded class */
1092 c->state &= ~CLASS_LOADING;
1099 /* load the component class */
1101 u = utf_new(text + 1, namelen - 1);
1103 if (!(comp = load_class_from_classloader(u, cl)))
1106 /* create the array class */
1108 c = class_array_of(comp, false);
1110 tmpc = classcache_store(cl, c, true);
1113 /* exception, free the loaded class */
1114 c->state &= ~CLASS_LOADING;
1121 /* primitive array classes are loaded by the bootstrap loader */
1123 c = load_class_bootstrap(name);
1129 LLNI_class_get(cl, c);
1131 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1132 /* OpenJDK uses this internal function because it's
1135 lc = class_resolveclassmethod(c,
1136 utf_loadClassInternal,
1137 utf_java_lang_String__java_lang_Class,
1141 lc = class_resolveclassmethod(c,
1143 utf_java_lang_String__java_lang_Class,
1149 return false; /* exception */
1151 /* move return value into `o' and cast it afterwards to a classinfo* */
1153 string = javastring_new_slash_to_dot(name);
1155 RT_TIMING_GET_TIME(time_prepare);
1157 o = vm_call_method(lc, (java_handle_t *) cl, string);
1159 RT_TIMING_GET_TIME(time_java);
1161 c = LLNI_classinfo_unwrap(o);
1164 /* Store this class in the loaded class cache. If another
1165 class with the same (initloader,name) pair has been
1166 stored earlier it will be returned by classcache_store
1167 In this case classcache_store may not free the class
1168 because it has already been exposed to Java code which
1169 may have kept references to that class. */
1171 tmpc = classcache_store(cl, c, false);
1174 /* exception, free the loaded class */
1175 c->state &= ~CLASS_LOADING;
1182 RT_TIMING_GET_TIME(time_cache);
1184 RT_TIMING_TIME_DIFF(time_lookup , time_prepare, RT_TIMING_LOAD_CL_PREPARE);
1185 RT_TIMING_TIME_DIFF(time_prepare, time_java , RT_TIMING_LOAD_CL_JAVA);
1186 RT_TIMING_TIME_DIFF(time_java , time_cache , RT_TIMING_LOAD_CL_CACHE);
1188 /* SUN compatible -verbose:class output */
1190 if (opt_verboseclass && (c != NULL) && (c->classloader == cl)) {
1192 utf_display_printable_ascii_classname(name);
1196 #if defined(ENABLE_JVMTI)
1197 /* fire Class Load JVMTI event */
1198 if (jvmti) jvmti_ClassLoadPrepare(false, c);
1205 c = load_class_bootstrap(name);
1211 /* load_class_bootstrap ********************************************************
1213 Load the class with the given name using the bootstrap class loader.
1216 name.............the classname
1219 loaded classinfo, or
1220 NULL if an exception has been thrown
1223 load_class_bootstrap is synchronized. It can be treated as an
1226 *******************************************************************************/
1228 classinfo *load_class_bootstrap(utf *name)
1233 #if defined(ENABLE_RT_TIMING)
1234 struct timespec time_start, time_lookup, time_array, time_suck,
1235 time_load, time_cache;
1238 RT_TIMING_GET_TIME(time_start);
1244 /* lookup if this class has already been loaded */
1246 r = classcache_lookup(NULL, name);
1249 RT_TIMING_GET_TIME(time_lookup);
1250 RT_TIMING_TIME_DIFF(time_start,time_lookup,RT_TIMING_LOAD_BOOT_LOOKUP);
1255 RT_TIMING_GET_TIME(time_lookup);
1256 RT_TIMING_TIME_DIFF(time_start,time_lookup,RT_TIMING_LOAD_BOOT_LOOKUP);
1258 /* create the classinfo */
1260 c = class_create_classinfo(name);
1262 /* handle array classes */
1264 if (name->text[0] == '[') {
1265 c = load_newly_created_array(c, NULL);
1270 assert(c->state & CLASS_LOADED);
1272 RT_TIMING_GET_TIME(time_array);
1273 RT_TIMING_TIME_DIFF(time_start,time_array,RT_TIMING_LOAD_BOOT_ARRAY);
1278 #if defined(ENABLE_STATISTICS)
1281 if (opt_getcompilingtime)
1282 compilingtime_stop();
1284 if (opt_getloadingtime)
1285 loadingtime_start();
1288 /* load classdata, throw exception on error */
1293 exceptions_throw_classnotfoundexception(name);
1297 RT_TIMING_GET_TIME(time_suck);
1299 /* load the class from the buffer */
1301 r = load_class_from_classbuffer(cb);
1303 RT_TIMING_GET_TIME(time_load);
1306 /* the class could not be loaded, free the classinfo struct */
1311 /* Store this class in the loaded class cache this step also
1312 checks the loading constraints. If the class has been
1313 loaded before, the earlier loaded class is returned. */
1315 classinfo *res = classcache_store(NULL, c, true);
1322 /* Add the package name to the boot packages. */
1324 Package_add(c->packagename);
1330 RT_TIMING_GET_TIME(time_cache);
1332 /* SUN compatible -verbose:class output */
1334 if (opt_verboseclass && r) {
1336 utf_display_printable_ascii_classname(name);
1337 printf(" from %s]\n", cb->path);
1344 #if defined(ENABLE_STATISTICS)
1347 if (opt_getloadingtime)
1350 if (opt_getcompilingtime)
1351 compilingtime_start();
1354 RT_TIMING_TIME_DIFF(time_lookup, time_suck , RT_TIMING_LOAD_BOOT_SUCK);
1355 RT_TIMING_TIME_DIFF(time_suck , time_load , RT_TIMING_LOAD_BOOT_LOAD);
1356 RT_TIMING_TIME_DIFF(time_load , time_cache, RT_TIMING_LOAD_BOOT_CACHE);
1357 RT_TIMING_TIME_DIFF(time_lookup, time_cache, RT_TIMING_LOAD_BOOT_TOTAL);
1363 /* load_class_from_classbuffer_intern ******************************************
1365 Loads a class from a classbuffer into a given classinfo structure.
1366 Super-classes are also loaded at this point and some verfication
1370 This function is NOT synchronized!
1372 *******************************************************************************/
1374 static bool load_class_from_classbuffer_intern(classbuffer *cb)
1380 utf **interfacesnames;
1382 constant_classref *cr;
1387 descriptor_pool *descpool;
1388 #if defined(ENABLE_STATISTICS)
1392 #if defined(ENABLE_RT_TIMING)
1393 struct timespec time_start, time_checks, time_ndpool, time_cpool,
1394 time_setup, time_fields, time_methods, time_classrefs,
1395 time_descs, time_setrefs, time_parsefds, time_parsemds,
1396 time_parsecpool, time_verify, time_attrs;
1399 RT_TIMING_GET_TIME(time_start);
1401 /* Get the classbuffer's class. */
1405 if (!suck_check_classbuffer_size(cb, 4 + 2 + 2))
1408 /* check signature */
1410 if (suck_u4(cb) != MAGIC) {
1411 exceptions_throw_classformaterror(c, "Bad magic number");
1420 if (!(ma < MAJOR_VERSION || (ma == MAJOR_VERSION && mi <= MINOR_VERSION))) {
1421 exceptions_throw_unsupportedclassversionerror(c, ma, mi);
1425 RT_TIMING_GET_TIME(time_checks);
1427 /* create a new descriptor pool */
1429 descpool = descriptor_pool_new(c);
1431 RT_TIMING_GET_TIME(time_ndpool);
1433 /* load the constant pool */
1435 if (!load_constantpool(cb, descpool))
1438 RT_TIMING_GET_TIME(time_cpool);
1442 if (!suck_check_classbuffer_size(cb, 2))
1445 /* We OR the flags here, as we set already some flags in
1446 class_create_classinfo. */
1448 c->flags |= suck_u2(cb);
1450 /* check ACC flags consistency */
1452 if (c->flags & ACC_INTERFACE) {
1453 if (!(c->flags & ACC_ABSTRACT)) {
1454 /* We work around this because interfaces in JDK 1.1 are
1455 * not declared abstract. */
1457 c->flags |= ACC_ABSTRACT;
1460 if (c->flags & ACC_FINAL) {
1461 exceptions_throw_classformaterror(c,
1462 "Illegal class modifiers: 0x%X",
1467 if (c->flags & ACC_SUPER) {
1468 c->flags &= ~ACC_SUPER; /* kjc seems to set this on interfaces */
1472 if ((c->flags & (ACC_ABSTRACT | ACC_FINAL)) == (ACC_ABSTRACT | ACC_FINAL)) {
1473 exceptions_throw_classformaterror(c,
1474 "Illegal class modifiers: 0x%X",
1479 if (!suck_check_classbuffer_size(cb, 2 + 2))
1484 index = suck_u2(cb);
1486 name = (utf *) class_getconstant(c, index, CONSTANT_Class);
1491 if (c->name == utf_not_named_yet) {
1492 /* we finally have a name for this class */
1494 class_set_packagename(c);
1496 else if (name != c->name) {
1497 exceptions_throw_noclassdeffounderror_wrong_name(c, name);
1501 /* Retrieve superclass. */
1505 index = suck_u2(cb);
1510 /* This is only allowed for java.lang.Object. */
1512 if (c->name != utf_java_lang_Object) {
1513 exceptions_throw_classformaterror(c, "Bad superclass index");
1518 supername = (utf *) class_getconstant(c, index, CONSTANT_Class);
1520 if (supername == NULL)
1523 /* java.lang.Object may not have a super class. */
1525 if (c->name == utf_java_lang_Object) {
1526 exceptions_throw_classformaterror(NULL, "java.lang.Object with superclass");
1530 /* Detect circularity. */
1532 if (supername == c->name) {
1533 exceptions_throw_classcircularityerror(c);
1537 /* Interfaces must have java.lang.Object as super class. */
1539 if ((c->flags & ACC_INTERFACE) && (supername != utf_java_lang_Object)) {
1540 exceptions_throw_classformaterror(c, "Interfaces must have java.lang.Object as superclass");
1545 /* Parse the super interfaces. */
1547 if (!suck_check_classbuffer_size(cb, 2))
1550 c->interfacescount = suck_u2(cb);
1552 if (!suck_check_classbuffer_size(cb, 2 * c->interfacescount))
1555 c->interfaces = MNEW(classinfo*, c->interfacescount);
1557 /* Get the names of the super interfaces. */
1559 interfacesnames = DMNEW(utf*, c->interfacescount);
1561 for (i = 0; i < c->interfacescount; i++) {
1562 index = suck_u2(cb);
1564 u = (utf *) class_getconstant(c, index, CONSTANT_Class);
1569 interfacesnames[i] = u;
1572 RT_TIMING_GET_TIME(time_setup);
1576 if (!suck_check_classbuffer_size(cb, 2))
1579 c->fieldscount = suck_u2(cb);
1580 c->fields = MNEW(fieldinfo, c->fieldscount);
1582 MZERO(c->fields, fieldinfo, c->fieldscount);
1584 for (i = 0; i < c->fieldscount; i++) {
1585 if (!field_load(cb, &(c->fields[i]), descpool))
1589 RT_TIMING_GET_TIME(time_fields);
1591 /* Parse methods. */
1593 if (!suck_check_classbuffer_size(cb, 2))
1596 c->methodscount = suck_u2(cb);
1597 c->methods = MNEW(methodinfo, c->methodscount);
1599 MZERO(c->methods, methodinfo, c->methodscount);
1601 for (i = 0; i < c->methodscount; i++) {
1602 if (!method_load(cb, &(c->methods[i]), descpool))
1606 RT_TIMING_GET_TIME(time_methods);
1608 /* create the class reference table */
1611 descriptor_pool_create_classrefs(descpool, &(c->classrefcount));
1613 RT_TIMING_GET_TIME(time_classrefs);
1615 /* allocate space for the parsed descriptors */
1617 descriptor_pool_alloc_parsed_descriptors(descpool);
1619 descriptor_pool_get_parsed_descriptors(descpool, &(c->parseddescsize));
1621 #if defined(ENABLE_STATISTICS)
1623 descriptor_pool_get_sizes(descpool, &classrefsize, &descsize);
1624 count_classref_len += classrefsize;
1625 count_parsed_desc_len += descsize;
1629 RT_TIMING_GET_TIME(time_descs);
1631 /* put the classrefs in the constant pool */
1633 for (i = 0; i < c->cpcount; i++) {
1634 if (c->cptags[i] == CONSTANT_Class) {
1635 utf *name = (utf *) c->cpinfos[i];
1636 c->cpinfos[i] = descriptor_pool_lookup_classref(descpool, name);
1640 /* Resolve the super class. */
1642 if (supername != NULL) {
1643 cr = descriptor_pool_lookup_classref(descpool, supername);
1648 /* XXX This should be done better. */
1649 tc = resolve_classref_or_classinfo_eager(CLASSREF_OR_CLASSINFO(cr), false);
1652 resolve_handle_pending_exception(true);
1656 /* Interfaces are not allowed as super classes. */
1658 if (tc->flags & ACC_INTERFACE) {
1659 exceptions_throw_incompatibleclasschangeerror(c, "class %s has interface %s as super class");
1663 /* Don't allow extending final classes */
1665 if (tc->flags & ACC_FINAL) {
1666 exceptions_throw_verifyerror(NULL,
1667 "Cannot inherit from final class");
1671 /* Store the super class. */
1676 /* Resolve the super interfaces. */
1678 for (i = 0; i < c->interfacescount; i++) {
1679 u = interfacesnames[i];
1680 cr = descriptor_pool_lookup_classref(descpool, u);
1685 /* XXX This should be done better. */
1686 tc = resolve_classref_or_classinfo_eager(CLASSREF_OR_CLASSINFO(cr), false);
1689 resolve_handle_pending_exception(true);
1693 /* Detect circularity. */
1696 exceptions_throw_classcircularityerror(c);
1700 if (!(tc->flags & ACC_INTERFACE)) {
1701 exceptions_throw_incompatibleclasschangeerror(tc,
1702 "Implementing class");
1706 /* Store the super interface. */
1708 c->interfaces[i] = tc;
1711 RT_TIMING_GET_TIME(time_setrefs);
1713 /* Parse the field descriptors. */
1715 for (i = 0; i < c->fieldscount; i++) {
1716 c->fields[i].parseddesc =
1717 descriptor_pool_parse_field_descriptor(descpool,
1718 c->fields[i].descriptor);
1719 if (!c->fields[i].parseddesc)
1723 RT_TIMING_GET_TIME(time_parsefds);
1725 /* parse method descriptors */
1727 for (i = 0; i < c->methodscount; i++) {
1728 methodinfo *m = &c->methods[i];
1730 descriptor_pool_parse_method_descriptor(descpool, m->descriptor,
1731 m->flags, class_get_self_classref(m->clazz));
1735 for (j = 0; j < m->rawexceptiontablelength; j++) {
1736 if (!m->rawexceptiontable[j].catchtype.any)
1739 if ((m->rawexceptiontable[j].catchtype.ref =
1740 descriptor_pool_lookup_classref(descpool,
1741 (utf *) m->rawexceptiontable[j].catchtype.any)) == NULL)
1745 for (j = 0; j < m->thrownexceptionscount; j++) {
1746 if (!m->thrownexceptions[j].any)
1749 if ((m->thrownexceptions[j].ref = descriptor_pool_lookup_classref(descpool,
1750 (utf *) m->thrownexceptions[j].any)) == NULL)
1755 RT_TIMING_GET_TIME(time_parsemds);
1757 /* parse the loaded descriptors */
1759 for (i = 0; i < c->cpcount; i++) {
1760 constant_FMIref *fmi;
1763 switch (c->cptags[i]) {
1764 case CONSTANT_Fieldref:
1765 fmi = (constant_FMIref *) c->cpinfos[i];
1766 fmi->parseddesc.fd =
1767 descriptor_pool_parse_field_descriptor(descpool,
1769 if (!fmi->parseddesc.fd)
1772 index = fmi->p.index;
1774 (constant_classref *) class_getconstant(c, index,
1776 if (!fmi->p.classref)
1779 case CONSTANT_Methodref:
1780 case CONSTANT_InterfaceMethodref:
1781 fmi = (constant_FMIref *) c->cpinfos[i];
1782 index = fmi->p.index;
1784 (constant_classref *) class_getconstant(c, index,
1786 if (!fmi->p.classref)
1788 fmi->parseddesc.md =
1789 descriptor_pool_parse_method_descriptor(descpool,
1793 if (!fmi->parseddesc.md)
1799 RT_TIMING_GET_TIME(time_parsecpool);
1801 #ifdef ENABLE_VERIFIER
1802 /* Check if all fields and methods can be uniquely
1803 * identified by (name,descriptor). */
1806 /* We use a hash table here to avoid making the
1807 * average case quadratic in # of methods, fields.
1809 static int shift = 0;
1811 u2 *next; /* for chaining colliding hash entries */
1817 /* Allocate hashtable */
1818 len = c->methodscount;
1819 if (len < c->fieldscount) len = c->fieldscount;
1821 hashtab = MNEW(u2,(hashlen + len));
1822 next = hashtab + hashlen;
1824 /* Determine bitshift (to get good hash values) */
1834 memset(hashtab, 0, sizeof(u2) * (hashlen + len));
1836 for (i = 0; i < c->fieldscount; ++i) {
1837 fieldinfo *fi = c->fields + i;
1839 /* It's ok if we lose bits here */
1840 index = ((((size_t) fi->name) +
1841 ((size_t) fi->descriptor)) >> shift) % hashlen;
1843 if ((old = hashtab[index])) {
1847 if (c->fields[old].name == fi->name &&
1848 c->fields[old].descriptor == fi->descriptor) {
1849 exceptions_throw_classformaterror(c, "Repetitive field name/signature");
1852 } while ((old = next[old]));
1854 hashtab[index] = i + 1;
1858 memset(hashtab, 0, sizeof(u2) * (hashlen + hashlen/5));
1860 for (i = 0; i < c->methodscount; ++i) {
1861 methodinfo *mi = c->methods + i;
1863 /* It's ok if we lose bits here */
1864 index = ((((size_t) mi->name) +
1865 ((size_t) mi->descriptor)) >> shift) % hashlen;
1867 if ((old = hashtab[index])) {
1871 if (c->methods[old].name == mi->name &&
1872 c->methods[old].descriptor == mi->descriptor) {
1873 exceptions_throw_classformaterror(c, "Repetitive method name/signature");
1876 } while ((old = next[old]));
1878 hashtab[index] = i + 1;
1881 MFREE(hashtab, u2, (hashlen + len));
1883 #endif /* ENABLE_VERIFIER */
1885 RT_TIMING_GET_TIME(time_verify);
1887 #if defined(ENABLE_STATISTICS)
1889 size_classinfo += sizeof(classinfo*) * c->interfacescount;
1890 size_fieldinfo += sizeof(fieldinfo) * c->fieldscount;
1891 size_methodinfo += sizeof(methodinfo) * c->methodscount;
1895 /* load attribute structures */
1897 if (!class_load_attributes(cb))
1900 /* Pre Java 1.5 version don't check this. This implementation is
1901 like Java 1.5 do it: for class file version 45.3 we don't check
1902 it, older versions are checked. */
1904 if (((ma == 45) && (mi > 3)) || (ma > 45)) {
1905 /* check if all data has been read */
1906 s4 classdata_left = ((cb->data + cb->size) - cb->pos);
1908 if (classdata_left > 0) {
1909 exceptions_throw_classformaterror(c, "Extra bytes at the end of class file");
1914 RT_TIMING_GET_TIME(time_attrs);
1916 RT_TIMING_TIME_DIFF(time_start , time_checks , RT_TIMING_LOAD_CHECKS);
1917 RT_TIMING_TIME_DIFF(time_checks , time_ndpool , RT_TIMING_LOAD_NDPOOL);
1918 RT_TIMING_TIME_DIFF(time_ndpool , time_cpool , RT_TIMING_LOAD_CPOOL);
1919 RT_TIMING_TIME_DIFF(time_cpool , time_setup , RT_TIMING_LOAD_SETUP);
1920 RT_TIMING_TIME_DIFF(time_setup , time_fields , RT_TIMING_LOAD_FIELDS);
1921 RT_TIMING_TIME_DIFF(time_fields , time_methods , RT_TIMING_LOAD_METHODS);
1922 RT_TIMING_TIME_DIFF(time_methods , time_classrefs , RT_TIMING_LOAD_CLASSREFS);
1923 RT_TIMING_TIME_DIFF(time_classrefs , time_descs , RT_TIMING_LOAD_DESCS);
1924 RT_TIMING_TIME_DIFF(time_descs , time_setrefs , RT_TIMING_LOAD_SETREFS);
1925 RT_TIMING_TIME_DIFF(time_setrefs , time_parsefds , RT_TIMING_LOAD_PARSEFDS);
1926 RT_TIMING_TIME_DIFF(time_parsefds , time_parsemds , RT_TIMING_LOAD_PARSEMDS);
1927 RT_TIMING_TIME_DIFF(time_parsemds , time_parsecpool, RT_TIMING_LOAD_PARSECP);
1928 RT_TIMING_TIME_DIFF(time_parsecpool, time_verify , RT_TIMING_LOAD_VERIFY);
1929 RT_TIMING_TIME_DIFF(time_verify , time_attrs , RT_TIMING_LOAD_ATTRS);
1930 RT_TIMING_TIME_DIFF(time_start , time_attrs , RT_TIMING_LOAD_TOTAL);
1936 /* load_class_from_classbuffer *************************************************
1938 Convenience wrapper for load_class_from_classbuffer.
1941 This function is NOT synchronized!
1943 *******************************************************************************/
1945 classinfo *load_class_from_classbuffer(classbuffer *cb)
1951 /* Get the classbuffer's class. */
1955 /* Check if the class is already loaded. */
1957 if (c->state & CLASS_LOADED)
1960 #if defined(ENABLE_STATISTICS)
1962 count_class_loads++;
1965 #if !defined(NDEBUG)
1967 log_message_class("Loading class: ", c);
1970 /* Mark start of dump memory area. */
1974 /* Class is currently loading. */
1976 c->state |= CLASS_LOADING;
1978 /* Parse the classbuffer. */
1980 result = load_class_from_classbuffer_intern(cb);
1982 /* Release dump area. */
1986 /* An error occurred. */
1988 if (result == false) {
1989 /* Revert loading state. */
1991 c->state = (c->state & ~CLASS_LOADING);
1996 /* Revert loading state and set loaded. */
1998 c->state = (c->state & ~CLASS_LOADING) | CLASS_LOADED;
2000 #if defined(ENABLE_JVMTI)
2001 /* fire Class Prepare JVMTI event */
2004 jvmti_ClassLoadPrepare(true, c);
2007 #if !defined(NDEBUG)
2009 log_message_class("Loading done class: ", c);
2016 /* load_newly_created_array ****************************************************
2018 Load a newly created array class.
2021 c....................the array class C has been loaded
2022 other classinfo......the array class was found in the class cache,
2024 NULL.................an exception has been thrown
2027 This is an internal function. Do not use it unless you know exactly
2030 Use one of the load_class_... functions for general array class loading.
2032 *******************************************************************************/
2034 classinfo *load_newly_created_array(classinfo *c, classloader_t *loader)
2036 classinfo *comp = NULL;
2038 methoddesc *clonedesc;
2039 constant_classref *classrefs;
2044 text = c->name->text;
2045 namelen = c->name->blength;
2047 /* Check array class name */
2049 if ((namelen < 2) || (text[0] != '[')) {
2050 exceptions_throw_classnotfoundexception(c->name);
2054 /* Check the element type */
2058 /* c is an array of arrays. We have to create the component class. */
2060 u = utf_new(text + 1, namelen - 1);
2062 comp = load_class_from_classloader(u, loader);
2067 assert(comp->state & CLASS_LOADED);
2069 /* the array's flags are that of the component class */
2070 c->flags = (comp->flags & ~ACC_INTERFACE) | ACC_FINAL | ACC_ABSTRACT;
2071 c->classloader = comp->classloader;
2075 /* c is an array of objects. */
2077 /* check for cases like `[L;' or `[L[I;' or `[Ljava.lang.Object' */
2078 if ((namelen < 4) || (text[2] == '[') || (text[namelen - 1] != ';')) {
2079 exceptions_throw_classnotfoundexception(c->name);
2083 u = utf_new(text + 2, namelen - 3);
2085 if (!(comp = load_class_from_classloader(u, loader)))
2088 assert(comp->state & CLASS_LOADED);
2090 /* the array's flags are that of the component class */
2091 c->flags = (comp->flags & ~ACC_INTERFACE) | ACC_FINAL | ACC_ABSTRACT;
2092 c->classloader = comp->classloader;
2096 /* c is an array of a primitive type */
2098 /* check for cases like `[II' and whether the character is a
2099 valid primitive type */
2101 if ((namelen > 2) || (Primitive_get_class_by_char(text[1]) == NULL)) {
2102 exceptions_throw_classnotfoundexception(c->name);
2106 /* the accessibility of the array class is public (VM Spec 5.3.3) */
2107 c->flags = ACC_PUBLIC | ACC_FINAL | ACC_ABSTRACT;
2108 c->classloader = NULL;
2111 assert(class_java_lang_Object);
2112 #if defined(ENABLE_JAVASE)
2113 assert(class_java_lang_Cloneable);
2114 assert(class_java_io_Serializable);
2117 /* Setup the array class. */
2119 c->super = class_java_lang_Object;
2121 #if defined(ENABLE_JAVASE)
2123 c->interfacescount = 2;
2124 c->interfaces = MNEW(classinfo*, 2);
2125 c->interfaces[0] = class_java_lang_Cloneable;
2126 c->interfaces[1] = class_java_io_Serializable;
2128 #elif defined(ENABLE_JAVAME_CLDC1_1)
2130 c->interfacescount = 0;
2131 c->interfaces = NULL;
2134 # error unknow Java configuration
2137 c->methodscount = 1;
2138 c->methods = MNEW(methodinfo, c->methodscount);
2140 MZERO(c->methods, methodinfo, c->methodscount);
2142 classrefs = MNEW(constant_classref, 2);
2144 CLASSREF_INIT(classrefs[0], c, c->name);
2145 CLASSREF_INIT(classrefs[1], c, utf_java_lang_Object);
2147 /* create descriptor for clone method */
2148 /* we need one paramslot which is reserved for the 'this' parameter */
2149 clonedesc = NEW(methoddesc);
2150 clonedesc->returntype.type = TYPE_ADR;
2151 clonedesc->returntype.classref = classrefs + 1;
2152 clonedesc->returntype.arraydim = 0;
2153 /* initialize params to "empty", add real params below in
2154 descriptor_params_from_paramtypes */
2155 clonedesc->paramcount = 0;
2156 clonedesc->paramslots = 0;
2157 clonedesc->paramtypes[0].classref = classrefs + 0;
2158 clonedesc->params = NULL;
2160 /* create methodinfo */
2163 MSET(clone, 0, methodinfo, 1);
2165 #if defined(ENABLE_THREADS)
2166 lock_init_object_lock(&clone->header);
2169 /* ATTENTION: if you delete the ACC_NATIVE below, set
2170 clone->maxlocals=1 (interpreter related) */
2172 clone->flags = ACC_PUBLIC | ACC_NATIVE;
2173 clone->name = utf_clone;
2174 clone->descriptor = utf_void__java_lang_Object;
2175 clone->parseddesc = clonedesc;
2178 /* parse the descriptor to get the register allocation */
2180 if (!descriptor_params_from_paramtypes(clonedesc, clone->flags))
2183 clone->code = NativeStub_generate(clone, BUILTIN_clone);
2185 /* XXX: field: length? */
2187 /* array classes are not loaded from class files */
2189 c->state |= CLASS_LOADED;
2190 c->parseddescs = (u1 *) clonedesc;
2191 c->parseddescsize = sizeof(methodinfo);
2192 c->classrefs = classrefs;
2193 c->classrefcount = 1;
2195 /* insert class into the loaded class cache */
2196 /* XXX free classinfo if NULL returned? */
2198 return classcache_store(loader, c, true);
2202 /* loader_close ****************************************************************
2204 Frees all resources.
2206 *******************************************************************************/
2208 void loader_close(void)
2215 * These are local overrides for various environment variables in Emacs.
2216 * Please do not remove this and leave it at the end of the file, where
2217 * Emacs will automagically detect them.
2218 * ---------------------------------------------------------------------
2221 * indent-tabs-mode: t
2225 * vim:noexpandtab:sw=4:ts=4: