1 /* src/vmcore/loader.c - class loader functions
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: loader.c 8324 2007-08-16 16:48:12Z michi $
38 #include "mm/memory.h"
40 #include "native/llni.h"
42 #include "threads/lock-common.h"
44 #include "toolbox/hashtable.h"
45 #include "toolbox/logging.h"
47 #include "vm/builtin.h"
48 #include "vm/exceptions.h"
49 #include "vm/global.h"
50 #include "vm/primitive.h"
51 #include "vm/stringlocal.h"
54 #include "vm/jit_interface.h"
56 #if defined(ENABLE_JAVASE)
57 # include "vmcore/annotation.h"
58 # include "vmcore/stackmap.h"
61 #include "vmcore/classcache.h"
62 #include "vmcore/field.h"
63 #include "vmcore/linker.h"
64 #include "vmcore/loader.h"
65 #include "vmcore/method.h"
66 #include "vmcore/options.h"
67 #include "vmcore/rt-timing.h"
69 #if defined(ENABLE_STATISTICS)
70 # include "vmcore/statistics.h"
73 #include "vmcore/suck.h"
75 #if defined(ENABLE_ZLIB)
76 # include "vmcore/zip.h"
79 #if defined(ENABLE_JVMTI)
80 # include "native/jvmti/cacaodbg.h"
84 /* global variables ***********************************************************/
86 static hashtable *hashtable_classloader;
89 /* loader_init *****************************************************************
91 Initializes all lists and loads all classes required for the system
94 *******************************************************************************/
96 bool loader_init(void)
98 #if defined(ENABLE_THREADS)
99 list_classpath_entry *lce;
101 /* Initialize the monitor pointer for zip/jar file locking. */
103 for (lce = list_first(list_classpath_entries); lce != NULL;
104 lce = list_next(list_classpath_entries, lce))
105 if (lce->type == CLASSPATH_ARCHIVE)
106 LOCK_INIT_OBJECT_LOCK(lce);
109 /* initialize classloader hashtable, 10 entries should be enough */
111 hashtable_classloader = NEW(hashtable);
112 hashtable_create(hashtable_classloader, 10);
114 /* load some important classes */
116 if (!(class_java_lang_Object = load_class_bootstrap(utf_java_lang_Object)))
119 if (!(class_java_lang_String = load_class_bootstrap(utf_java_lang_String)))
122 #if defined(ENABLE_JAVASE)
123 if (!(class_java_lang_Cloneable =
124 load_class_bootstrap(utf_java_lang_Cloneable)))
127 if (!(class_java_io_Serializable =
128 load_class_bootstrap(utf_java_io_Serializable)))
132 /* load classes for wrapping primitive types */
134 #if defined(ENABLE_JAVASE)
135 if (!(class_java_lang_Void = load_class_bootstrap(utf_java_lang_Void)))
139 if (!(class_java_lang_Boolean =
140 load_class_bootstrap(utf_java_lang_Boolean)))
143 if (!(class_java_lang_Byte = load_class_bootstrap(utf_java_lang_Byte)))
146 if (!(class_java_lang_Character =
147 load_class_bootstrap(utf_java_lang_Character)))
150 if (!(class_java_lang_Short = load_class_bootstrap(utf_java_lang_Short)))
153 if (!(class_java_lang_Integer =
154 load_class_bootstrap(utf_java_lang_Integer)))
157 if (!(class_java_lang_Long = load_class_bootstrap(utf_java_lang_Long)))
160 if (!(class_java_lang_Float = load_class_bootstrap(utf_java_lang_Float)))
163 if (!(class_java_lang_Double = load_class_bootstrap(utf_java_lang_Double)))
167 /* load some other important classes */
169 if (!(class_java_lang_Class = load_class_bootstrap(utf_java_lang_Class)))
172 #if defined(ENABLE_JAVASE)
173 if (!(class_java_lang_ClassLoader =
174 load_class_bootstrap(utf_java_lang_ClassLoader)))
177 if (!(class_java_lang_SecurityManager =
178 load_class_bootstrap(utf_java_lang_SecurityManager)))
182 if (!(class_java_lang_System = load_class_bootstrap(utf_java_lang_System)))
185 if (!(class_java_lang_Thread =
186 load_class_bootstrap(utf_new_char("java/lang/Thread"))))
189 #if defined(ENABLE_JAVASE)
190 if (!(class_java_lang_ThreadGroup =
191 load_class_bootstrap(utf_java_lang_ThreadGroup)))
195 #if defined(WITH_CLASSPATH_GNU)
196 if (!(class_java_lang_VMSystem =
197 load_class_bootstrap(utf_new_char("java/lang/VMSystem"))))
201 if (!(class_java_lang_VMThread =
202 load_class_bootstrap(utf_new_char("java/lang/VMThread"))))
207 /* some classes which may be used more often */
209 #if defined(ENABLE_JAVASE)
210 if (!(class_java_lang_StackTraceElement =
211 load_class_bootstrap(utf_java_lang_StackTraceElement)))
214 if (!(class_java_lang_reflect_Constructor =
215 load_class_bootstrap(utf_java_lang_reflect_Constructor)))
218 if (!(class_java_lang_reflect_Field =
219 load_class_bootstrap(utf_java_lang_reflect_Field)))
222 if (!(class_java_lang_reflect_Method =
223 load_class_bootstrap(utf_java_lang_reflect_Method)))
226 if (!(class_java_security_PrivilegedAction =
227 load_class_bootstrap(utf_new_char("java/security/PrivilegedAction"))))
230 if (!(class_java_util_Vector = load_class_bootstrap(utf_java_util_Vector)))
233 # if defined(WITH_CLASSPATH_SUN)
234 if (!(class_sun_reflect_MagicAccessorImpl =
235 load_class_bootstrap(utf_new_char("sun/reflect/MagicAccessorImpl"))))
239 if (!(arrayclass_java_lang_Object =
240 load_class_bootstrap(utf_new_char("[Ljava/lang/Object;"))))
243 #if defined(ENABLE_ANNOTATIONS)
244 /* needed by annotation support */
245 if (!(class_sun_reflect_ConstantPool =
246 load_class_bootstrap(utf_sun_reflect_ConstantPool)))
249 #if defined(WITH_CLASSPATH_GNU)
250 /* needed by GNU Classpaths annotation support */
251 if (!(class_sun_reflect_annotation_AnnotationParser =
252 load_class_bootstrap(utf_sun_reflect_annotation_AnnotationParser)))
263 /* loader_hashtable_classloader_add ********************************************
265 Adds an entry to the classloader hashtable.
267 REMEMBER: Also use this to register native loaders!
269 *******************************************************************************/
271 classloader *loader_hashtable_classloader_add(java_handle_t *cl)
273 hashtable_classloader_entry *cle;
280 LOCK_MONITOR_ENTER(hashtable_classloader->header);
284 /* key for entry is the hashcode of the classloader;
285 aligned to 16-byte boundaries */
287 #if defined(ENABLE_GC_CACAO)
288 key = heap_get_hashcode(LLNI_direct(cl)) >> 4;
290 key = ((u4) (ptrint) cl) >> 4;
293 slot = key & (hashtable_classloader->size - 1);
294 cle = hashtable_classloader->ptr[slot];
296 /* search hashchain for existing entry */
299 if (cle->object == LLNI_direct(cl))
307 /* if no classloader was found, we create a new entry here */
310 cle = NEW(hashtable_classloader_entry);
312 #if defined(ENABLE_GC_CACAO)
313 /* register the classloader object with the GC */
315 gc_reference_register(&(cle->object));
320 cle->object = LLNI_direct(cl);
324 /* insert entry into hashtable */
326 cle->hashlink = hashtable_classloader->ptr[slot];
327 hashtable_classloader->ptr[slot] = cle;
329 /* update number of entries */
331 hashtable_classloader->entries++;
335 LOCK_MONITOR_EXIT(hashtable_classloader->header);
341 /* loader_hashtable_classloader_find *******************************************
343 Find an entry in the classloader hashtable.
345 *******************************************************************************/
347 classloader *loader_hashtable_classloader_find(java_handle_t *cl)
349 hashtable_classloader_entry *cle;
358 /* key for entry is the hashcode of the classloader;
359 aligned to 16-byte boundaries */
361 #if defined(ENABLE_GC_CACAO)
362 key = heap_get_hashcode(LLNI_direct(cl)) >> 4;
364 key = ((u4) (ptrint) cl) >> 4;
367 slot = key & (hashtable_classloader->size - 1);
368 cle = hashtable_classloader->ptr[slot];
370 /* search hashchain for existing entry */
373 if (cle->object == LLNI_direct(cl))
385 /* loader_load_all_classes *****************************************************
387 Loads all classes specified in the BOOTCLASSPATH.
389 *******************************************************************************/
391 void loader_load_all_classes(void)
393 list_classpath_entry *lce;
394 #if defined(ENABLE_ZLIB)
397 hashtable_zipfile_entry *htzfe;
401 for (lce = list_first(list_classpath_entries); lce != NULL;
402 lce = list_next(list_classpath_entries, lce)) {
403 #if defined(ENABLE_ZLIB)
404 if (lce->type == CLASSPATH_ARCHIVE) {
405 /* get the classes hashtable */
409 for (slot = 0; slot < ht->size; slot++) {
410 htzfe = (hashtable_zipfile_entry *) ht->ptr[slot];
412 for (; htzfe; htzfe = htzfe->hashlink) {
415 /* skip all entries in META-INF and .properties,
418 if (!strncmp(u->text, "META-INF", strlen("META-INF")) ||
419 strstr(u->text, ".properties") ||
420 strstr(u->text, ".png"))
423 /* load class from bootstrap classloader */
425 if (!load_class_bootstrap(u)) {
426 fprintf(stderr, "Error loading: ");
427 utf_fprint_printable_ascii_classname(stderr, u);
428 fprintf(stderr, "\n");
431 /* print out exception and cause */
433 exceptions_print_current_exception();
441 #if defined(ENABLE_ZLIB)
448 /* loader_skip_attribute_body **************************************************
450 Skips an attribute the attribute_name_index has already been read.
453 u2 attribute_name_index;
455 u1 info[attribute_length];
458 *******************************************************************************/
460 bool loader_skip_attribute_body(classbuffer *cb)
464 if (!suck_check_classbuffer_size(cb, 4))
467 attribute_length = suck_u4(cb);
469 if (!suck_check_classbuffer_size(cb, attribute_length))
472 suck_skip_nbytes(cb, attribute_length);
478 /* load_constantpool ***********************************************************
480 Loads the constantpool of a class, the entries are transformed into
481 a simpler format by resolving references (a detailed overview of
482 the compact structures can be found in global.h).
484 *******************************************************************************/
486 static bool load_constantpool(classbuffer *cb, descriptor_pool *descpool)
489 /* The following structures are used to save information which cannot be
490 processed during the first pass. After the complete constantpool has
491 been traversed the references can be resolved.
492 (only in specific order) */
494 /* CONSTANT_Class entries */
495 typedef struct forward_class {
496 struct forward_class *next;
501 /* CONSTANT_String */
502 typedef struct forward_string {
503 struct forward_string *next;
508 /* CONSTANT_NameAndType */
509 typedef struct forward_nameandtype {
510 struct forward_nameandtype *next;
514 } forward_nameandtype;
516 /* CONSTANT_Fieldref, CONSTANT_Methodref or CONSTANT_InterfaceMethodref */
517 typedef struct forward_fieldmethint {
518 struct forward_fieldmethint *next;
522 u2 nameandtype_index;
523 } forward_fieldmethint;
529 forward_class *forward_classes = NULL;
530 forward_string *forward_strings = NULL;
531 forward_nameandtype *forward_nameandtypes = NULL;
532 forward_fieldmethint *forward_fieldmethints = NULL;
536 forward_nameandtype *nfn;
537 forward_fieldmethint *nff;
545 /* number of entries in the constant_pool table plus one */
546 if (!suck_check_classbuffer_size(cb, 2))
549 cpcount = c->cpcount = suck_u2(cb);
551 /* allocate memory */
552 cptags = c->cptags = MNEW(u1, cpcount);
553 cpinfos = c->cpinfos = MNEW(voidptr, cpcount);
556 exceptions_throw_classformaterror(c, "Illegal constant pool size");
560 #if defined(ENABLE_STATISTICS)
562 count_const_pool_len += (sizeof(u1) + sizeof(voidptr)) * cpcount;
565 /* initialize constantpool */
566 for (idx = 0; idx < cpcount; idx++) {
567 cptags[idx] = CONSTANT_UNUSED;
572 /******* first pass *******/
573 /* entries which cannot be resolved now are written into
574 temporary structures and traversed again later */
577 while (idx < cpcount) {
580 /* get constant type */
581 if (!suck_check_classbuffer_size(cb, 1))
588 nfc = DNEW(forward_class);
590 nfc->next = forward_classes;
591 forward_classes = nfc;
593 nfc->thisindex = idx;
594 /* reference to CONSTANT_NameAndType */
595 if (!suck_check_classbuffer_size(cb, 2))
598 nfc->name_index = suck_u2(cb);
603 case CONSTANT_String:
604 nfs = DNEW(forward_string);
606 nfs->next = forward_strings;
607 forward_strings = nfs;
609 nfs->thisindex = idx;
611 /* reference to CONSTANT_Utf8_info with string characters */
612 if (!suck_check_classbuffer_size(cb, 2))
615 nfs->string_index = suck_u2(cb);
620 case CONSTANT_NameAndType:
621 nfn = DNEW(forward_nameandtype);
623 nfn->next = forward_nameandtypes;
624 forward_nameandtypes = nfn;
626 nfn->thisindex = idx;
628 if (!suck_check_classbuffer_size(cb, 2 + 2))
631 /* reference to CONSTANT_Utf8_info containing simple name */
632 nfn->name_index = suck_u2(cb);
634 /* reference to CONSTANT_Utf8_info containing field or method
636 nfn->sig_index = suck_u2(cb);
641 case CONSTANT_Fieldref:
642 case CONSTANT_Methodref:
643 case CONSTANT_InterfaceMethodref:
644 nff = DNEW(forward_fieldmethint);
646 nff->next = forward_fieldmethints;
647 forward_fieldmethints = nff;
649 nff->thisindex = idx;
653 if (!suck_check_classbuffer_size(cb, 2 + 2))
656 /* class or interface type that contains the declaration of the
658 nff->class_index = suck_u2(cb);
660 /* name and descriptor of the field or method */
661 nff->nameandtype_index = suck_u2(cb);
666 case CONSTANT_Integer: {
667 constant_integer *ci = NEW(constant_integer);
669 #if defined(ENABLE_STATISTICS)
671 count_const_pool_len += sizeof(constant_integer);
674 if (!suck_check_classbuffer_size(cb, 4))
677 ci->value = suck_s4(cb);
678 cptags[idx] = CONSTANT_Integer;
685 case CONSTANT_Float: {
686 constant_float *cf = NEW(constant_float);
688 #if defined(ENABLE_STATISTICS)
690 count_const_pool_len += sizeof(constant_float);
693 if (!suck_check_classbuffer_size(cb, 4))
696 cf->value = suck_float(cb);
697 cptags[idx] = CONSTANT_Float;
704 case CONSTANT_Long: {
705 constant_long *cl = NEW(constant_long);
707 #if defined(ENABLE_STATISTICS)
709 count_const_pool_len += sizeof(constant_long);
712 if (!suck_check_classbuffer_size(cb, 8))
715 cl->value = suck_s8(cb);
716 cptags[idx] = CONSTANT_Long;
720 exceptions_throw_classformaterror(c, "Invalid constant pool entry");
726 case CONSTANT_Double: {
727 constant_double *cd = NEW(constant_double);
729 #if defined(ENABLE_STATISTICS)
731 count_const_pool_len += sizeof(constant_double);
734 if (!suck_check_classbuffer_size(cb, 8))
737 cd->value = suck_double(cb);
738 cptags[idx] = CONSTANT_Double;
742 exceptions_throw_classformaterror(c, "Invalid constant pool entry");
748 case CONSTANT_Utf8: {
751 /* number of bytes in the bytes array (not string-length) */
752 if (!suck_check_classbuffer_size(cb, 2))
755 length = suck_u2(cb);
756 cptags[idx] = CONSTANT_Utf8;
758 /* validate the string */
759 if (!suck_check_classbuffer_size(cb, length))
762 #ifdef ENABLE_VERIFIER
764 !is_valid_utf((char *) cb->pos, (char *) (cb->pos + length)))
766 exceptions_throw_classformaterror(c, "Invalid UTF-8 string");
769 #endif /* ENABLE_VERIFIER */
770 /* insert utf-string into the utf-symboltable */
771 cpinfos[idx] = utf_new((char *) cb->pos, length);
773 /* skip bytes of the string (buffer size check above) */
774 suck_skip_nbytes(cb, length);
780 exceptions_throw_classformaterror(c, "Illegal constant pool type");
786 /* resolve entries in temporary structures */
788 while (forward_classes) {
790 class_getconstant(c, forward_classes->name_index, CONSTANT_Utf8);
794 #ifdef ENABLE_VERIFIER
795 if (opt_verify && !is_valid_name_utf(name)) {
796 exceptions_throw_classformaterror(c, "Class reference with invalid name");
799 #endif /* ENABLE_VERIFIER */
801 /* add all class references to the descriptor_pool */
803 if (!descriptor_pool_add_class(descpool, name))
806 cptags[forward_classes->thisindex] = CONSTANT_Class;
808 /* the classref is created later */
809 cpinfos[forward_classes->thisindex] = name;
811 nfc = forward_classes;
812 forward_classes = forward_classes->next;
815 while (forward_strings) {
817 class_getconstant(c, forward_strings->string_index, CONSTANT_Utf8);
821 /* resolve utf-string */
822 cptags[forward_strings->thisindex] = CONSTANT_String;
823 cpinfos[forward_strings->thisindex] = text;
825 nfs = forward_strings;
826 forward_strings = forward_strings->next;
829 while (forward_nameandtypes) {
830 constant_nameandtype *cn = NEW(constant_nameandtype);
832 #if defined(ENABLE_STATISTICS)
834 count_const_pool_len += sizeof(constant_nameandtype);
837 /* resolve simple name and descriptor */
838 cn->name = class_getconstant(c,
839 forward_nameandtypes->name_index,
844 cn->descriptor = class_getconstant(c,
845 forward_nameandtypes->sig_index,
850 #ifdef ENABLE_VERIFIER
853 if (!is_valid_name_utf(cn->name)) {
854 exceptions_throw_classformaterror(c,
855 "Illegal Field name \"%s\"",
861 /* disallow referencing <clinit> among others */
862 if (cn->name->text[0] == '<' && cn->name != utf_init) {
863 exceptions_throw_classformaterror(c, "Illegal reference to special method");
867 #endif /* ENABLE_VERIFIER */
869 cptags[forward_nameandtypes->thisindex] = CONSTANT_NameAndType;
870 cpinfos[forward_nameandtypes->thisindex] = cn;
872 nfn = forward_nameandtypes;
873 forward_nameandtypes = forward_nameandtypes->next;
876 while (forward_fieldmethints) {
877 constant_nameandtype *nat;
878 constant_FMIref *fmi = NEW(constant_FMIref);
880 #if defined(ENABLE_STATISTICS)
882 count_const_pool_len += sizeof(constant_FMIref);
884 /* resolve simple name and descriptor */
886 nat = class_getconstant(c,
887 forward_fieldmethints->nameandtype_index,
888 CONSTANT_NameAndType);
892 /* add all descriptors in {Field,Method}ref to the descriptor_pool */
894 if (!descriptor_pool_add(descpool, nat->descriptor, NULL))
897 /* the classref is created later */
899 fmi->p.index = forward_fieldmethints->class_index;
900 fmi->name = nat->name;
901 fmi->descriptor = nat->descriptor;
903 cptags[forward_fieldmethints->thisindex] = forward_fieldmethints->tag;
904 cpinfos[forward_fieldmethints->thisindex] = fmi;
906 nff = forward_fieldmethints;
907 forward_fieldmethints = forward_fieldmethints->next;
910 /* everything was ok */
916 /* loader_load_attribute_signature *********************************************
918 Signature_attribute {
919 u2 attribute_name_index;
924 *******************************************************************************/
926 #if defined(ENABLE_JAVASE)
927 bool loader_load_attribute_signature(classbuffer *cb, utf **signature)
937 /* check remaining bytecode */
939 if (!suck_check_classbuffer_size(cb, 4 + 2))
942 /* check attribute length */
944 attribute_length = suck_u4(cb);
946 if (attribute_length != 2) {
947 exceptions_throw_classformaterror(c, "Wrong size for VALUE attribute");
951 if (*signature != NULL) {
952 exceptions_throw_classformaterror(c, "Multiple Signature attributes");
958 signature_index = suck_u2(cb);
960 if (!(*signature = class_getconstant(c, signature_index, CONSTANT_Utf8)))
965 #endif /* defined(ENABLE_JAVASE) */
968 /* load_class_from_sysloader ***************************************************
970 Load the class with the given name using the system class loader
973 name.............the classname
977 NULL if an exception has been thrown
979 *******************************************************************************/
981 classinfo *load_class_from_sysloader(utf *name)
988 assert(class_java_lang_Object);
989 assert(class_java_lang_ClassLoader);
990 assert(class_java_lang_ClassLoader->state & CLASS_LINKED);
992 m = class_resolveclassmethod(class_java_lang_ClassLoader,
993 utf_getSystemClassLoader,
994 utf_void__java_lang_ClassLoader,
995 class_java_lang_Object,
1001 clo = vm_call_method(m, NULL);
1006 cl = loader_hashtable_classloader_add(clo);
1008 c = load_class_from_classloader(name, cl);
1014 /* load_class_from_classloader *************************************************
1016 Load the class with the given name using the given user-defined class loader.
1019 name.............the classname
1020 cl...............user-defined class loader
1023 the loaded class, or
1024 NULL if an exception has been thrown
1026 *******************************************************************************/
1028 classinfo *load_class_from_classloader(utf *name, classloader *cl)
1033 java_handle_t *string;
1034 #if defined(ENABLE_RT_TIMING)
1035 struct timespec time_start, time_lookup, time_prepare, time_java,
1039 RT_TIMING_GET_TIME(time_start);
1043 /* lookup if this class has already been loaded */
1045 c = classcache_lookup(cl, name);
1047 RT_TIMING_GET_TIME(time_lookup);
1048 RT_TIMING_TIME_DIFF(time_start,time_lookup,RT_TIMING_LOAD_CL_LOOKUP);
1053 /* if other class loader than bootstrap, call it */
1061 namelen = name->blength;
1063 /* handle array classes */
1064 if (text[0] == '[') {
1070 /* check for cases like `[L;' or `[L[I;' or `[Ljava.lang.Object' */
1071 if (namelen < 4 || text[2] == '[' || text[namelen - 1] != ';') {
1072 exceptions_throw_classnotfoundexception(name);
1076 u = utf_new(text + 2, namelen - 3);
1078 if (!(comp = load_class_from_classloader(u, cl)))
1081 /* create the array class */
1083 c = class_array_of(comp, false);
1085 tmpc = classcache_store(cl, c, true);
1088 /* exception, free the loaded class */
1089 c->state &= ~CLASS_LOADING;
1096 /* load the component class */
1098 u = utf_new(text + 1, namelen - 1);
1100 if (!(comp = load_class_from_classloader(u, cl)))
1103 /* create the array class */
1105 c = class_array_of(comp, false);
1107 tmpc = classcache_store(cl, c, true);
1110 /* exception, free the loaded class */
1111 c->state &= ~CLASS_LOADING;
1118 /* primitive array classes are loaded by the bootstrap loader */
1120 c = load_class_bootstrap(name);
1126 assert(class_java_lang_Object);
1128 lc = class_resolveclassmethod(cl->object->vftbl->class,
1130 utf_java_lang_String__java_lang_Class,
1131 class_java_lang_Object,
1135 return false; /* exception */
1137 /* move return value into `o' and cast it afterwards to a classinfo* */
1139 string = javastring_new_slash_to_dot(name);
1141 RT_TIMING_GET_TIME(time_prepare);
1143 o = vm_call_method(lc, (java_handle_t *) cl, string);
1145 RT_TIMING_GET_TIME(time_java);
1147 c = (classinfo *) o;
1150 /* Store this class in the loaded class cache. If another
1151 class with the same (initloader,name) pair has been
1152 stored earlier it will be returned by classcache_store
1153 In this case classcache_store may not free the class
1154 because it has already been exposed to Java code which
1155 may have kept references to that class. */
1157 tmpc = classcache_store(cl, c, false);
1160 /* exception, free the loaded class */
1161 c->state &= ~CLASS_LOADING;
1168 RT_TIMING_GET_TIME(time_cache);
1170 RT_TIMING_TIME_DIFF(time_lookup , time_prepare, RT_TIMING_LOAD_CL_PREPARE);
1171 RT_TIMING_TIME_DIFF(time_prepare, time_java , RT_TIMING_LOAD_CL_JAVA);
1172 RT_TIMING_TIME_DIFF(time_java , time_cache , RT_TIMING_LOAD_CL_CACHE);
1174 /* SUN compatible -verbose:class output */
1176 if (opt_verboseclass && (c != NULL) && (c->classloader == cl)) {
1178 utf_display_printable_ascii_classname(name);
1182 #if defined(ENABLE_JVMTI)
1183 /* fire Class Load JVMTI event */
1184 if (jvmti) jvmti_ClassLoadPrepare(false, c);
1191 c = load_class_bootstrap(name);
1197 /* load_class_bootstrap ********************************************************
1199 Load the class with the given name using the bootstrap class loader.
1202 name.............the classname
1205 loaded classinfo, or
1206 NULL if an exception has been thrown
1209 load_class_bootstrap is synchronized. It can be treated as an
1212 *******************************************************************************/
1214 classinfo *load_class_bootstrap(utf *name)
1219 #if defined(ENABLE_RT_TIMING)
1220 struct timespec time_start, time_lookup, time_array, time_suck,
1221 time_load, time_cache;
1224 RT_TIMING_GET_TIME(time_start);
1230 /* lookup if this class has already been loaded */
1232 r = classcache_lookup(NULL, name);
1235 RT_TIMING_GET_TIME(time_lookup);
1236 RT_TIMING_TIME_DIFF(time_start,time_lookup,RT_TIMING_LOAD_BOOT_LOOKUP);
1241 RT_TIMING_GET_TIME(time_lookup);
1242 RT_TIMING_TIME_DIFF(time_start,time_lookup,RT_TIMING_LOAD_BOOT_LOOKUP);
1244 /* create the classinfo */
1246 c = class_create_classinfo(name);
1248 /* handle array classes */
1250 if (name->text[0] == '[') {
1251 c = load_newly_created_array(c, NULL);
1256 assert(c->state & CLASS_LOADED);
1258 RT_TIMING_GET_TIME(time_array);
1259 RT_TIMING_TIME_DIFF(time_start,time_array,RT_TIMING_LOAD_BOOT_ARRAY);
1264 #if defined(ENABLE_STATISTICS)
1267 if (opt_getcompilingtime)
1268 compilingtime_stop();
1270 if (opt_getloadingtime)
1271 loadingtime_start();
1274 /* load classdata, throw exception on error */
1279 /* this normally means, the classpath was not set properly */
1281 if (name == utf_java_lang_Object)
1282 vm_abort("java/lang/NoClassDefFoundError: java/lang/Object");
1284 exceptions_throw_classnotfoundexception(name);
1289 RT_TIMING_GET_TIME(time_suck);
1291 /* load the class from the buffer */
1293 r = load_class_from_classbuffer(cb);
1295 RT_TIMING_GET_TIME(time_load);
1298 /* the class could not be loaded, free the classinfo struct */
1303 /* Store this class in the loaded class cache this step also
1304 checks the loading constraints. If the class has been loaded
1305 before, the earlier loaded class is returned. */
1307 classinfo *res = classcache_store(NULL, c, true);
1317 RT_TIMING_GET_TIME(time_cache);
1319 /* SUN compatible -verbose:class output */
1321 if (opt_verboseclass && r) {
1323 utf_display_printable_ascii_classname(name);
1324 printf(" from %s]\n", cb->path);
1331 #if defined(ENABLE_STATISTICS)
1334 if (opt_getloadingtime)
1337 if (opt_getcompilingtime)
1338 compilingtime_start();
1341 RT_TIMING_TIME_DIFF(time_lookup, time_suck , RT_TIMING_LOAD_BOOT_SUCK);
1342 RT_TIMING_TIME_DIFF(time_suck , time_load , RT_TIMING_LOAD_BOOT_LOAD);
1343 RT_TIMING_TIME_DIFF(time_load , time_cache, RT_TIMING_LOAD_BOOT_CACHE);
1344 RT_TIMING_TIME_DIFF(time_lookup, time_cache, RT_TIMING_LOAD_BOOT_TOTAL);
1350 /* load_class_from_classbuffer *************************************************
1352 Loads everything interesting about a class from the class file. The
1353 'classinfo' structure must have been allocated previously.
1355 The super class and the interfaces implemented by this class need
1356 not be loaded. The link is set later by the function 'class_link'.
1359 This function is NOT synchronized!
1361 *******************************************************************************/
1363 classinfo *load_class_from_classbuffer(classbuffer *cb)
1371 descriptor_pool *descpool;
1372 #if defined(ENABLE_STATISTICS)
1376 #if defined(ENABLE_RT_TIMING)
1377 struct timespec time_start, time_checks, time_ndpool, time_cpool,
1378 time_setup, time_fields, time_methods, time_classrefs,
1379 time_descs, time_setrefs, time_parsefds, time_parsemds,
1380 time_parsecpool, time_verify, time_attrs;
1383 RT_TIMING_GET_TIME(time_start);
1385 /* get the classbuffer's class */
1389 /* the class is already loaded */
1391 if (c->state & CLASS_LOADED)
1394 #if defined(ENABLE_STATISTICS)
1396 count_class_loads++;
1399 #if !defined(NDEBUG)
1400 /* output for debugging purposes */
1403 log_message_class("Loading class: ", c);
1406 /* mark start of dump memory area */
1408 dumpsize = dump_size();
1410 /* class is currently loading */
1412 c->state |= CLASS_LOADING;
1414 if (!suck_check_classbuffer_size(cb, 4 + 2 + 2))
1415 goto return_exception;
1417 /* check signature */
1419 if (suck_u4(cb) != MAGIC) {
1420 exceptions_throw_classformaterror(c, "Bad magic number");
1422 goto return_exception;
1430 if (!(ma < MAJOR_VERSION || (ma == MAJOR_VERSION && mi <= MINOR_VERSION))) {
1431 exceptions_throw_unsupportedclassversionerror(c, ma, mi);
1432 goto return_exception;
1435 RT_TIMING_GET_TIME(time_checks);
1437 /* create a new descriptor pool */
1439 descpool = descriptor_pool_new(c);
1441 RT_TIMING_GET_TIME(time_ndpool);
1443 /* load the constant pool */
1445 if (!load_constantpool(cb, descpool))
1446 goto return_exception;
1448 RT_TIMING_GET_TIME(time_cpool);
1452 if (!suck_check_classbuffer_size(cb, 2))
1453 goto return_exception;
1455 /* We OR the flags here, as we set already some flags in
1456 class_create_classinfo. */
1458 c->flags |= suck_u2(cb);
1460 /* check ACC flags consistency */
1462 if (c->flags & ACC_INTERFACE) {
1463 if (!(c->flags & ACC_ABSTRACT)) {
1464 /* We work around this because interfaces in JDK 1.1 are
1465 * not declared abstract. */
1467 c->flags |= ACC_ABSTRACT;
1470 if (c->flags & ACC_FINAL) {
1471 exceptions_throw_classformaterror(c,
1472 "Illegal class modifiers: 0x%X",
1474 goto return_exception;
1477 if (c->flags & ACC_SUPER) {
1478 c->flags &= ~ACC_SUPER; /* kjc seems to set this on interfaces */
1482 if ((c->flags & (ACC_ABSTRACT | ACC_FINAL)) == (ACC_ABSTRACT | ACC_FINAL)) {
1483 exceptions_throw_classformaterror(c,
1484 "Illegal class modifiers: 0x%X",
1486 goto return_exception;
1489 if (!suck_check_classbuffer_size(cb, 2 + 2))
1490 goto return_exception;
1496 if (!(name = (utf *) class_getconstant(c, i, CONSTANT_Class)))
1497 goto return_exception;
1499 if (c->name == utf_not_named_yet) {
1500 /* we finally have a name for this class */
1502 class_set_packagename(c);
1504 else if (name != c->name) {
1505 exceptions_throw_noclassdeffounderror_wrong_name(c, name);
1506 goto return_exception;
1509 /* retrieve superclass */
1511 c->super.any = NULL;
1513 if ((i = suck_u2(cb))) {
1514 if (!(supername = (utf *) class_getconstant(c, i, CONSTANT_Class)))
1515 goto return_exception;
1517 /* java.lang.Object may not have a super class. */
1519 if (c->name == utf_java_lang_Object) {
1520 exceptions_throw_classformaterror(NULL, "java.lang.Object with superclass");
1521 goto return_exception;
1524 /* Interfaces must have java.lang.Object as super class. */
1526 if ((c->flags & ACC_INTERFACE) && (supername != utf_java_lang_Object)) {
1527 exceptions_throw_classformaterror(c, "Interfaces must have java.lang.Object as superclass");
1528 goto return_exception;
1534 /* This is only allowed for java.lang.Object. */
1536 if (c->name != utf_java_lang_Object) {
1537 exceptions_throw_classformaterror(c, "Bad superclass index");
1538 goto return_exception;
1542 /* retrieve interfaces */
1544 if (!suck_check_classbuffer_size(cb, 2))
1545 goto return_exception;
1547 c->interfacescount = suck_u2(cb);
1549 if (!suck_check_classbuffer_size(cb, 2 * c->interfacescount))
1550 goto return_exception;
1552 c->interfaces = MNEW(classref_or_classinfo, c->interfacescount);
1553 for (i = 0; i < c->interfacescount; i++) {
1554 /* the classrefs are created later */
1555 if (!(c->interfaces[i].any = (utf *) class_getconstant(c, suck_u2(cb), CONSTANT_Class)))
1556 goto return_exception;
1559 RT_TIMING_GET_TIME(time_setup);
1563 if (!suck_check_classbuffer_size(cb, 2))
1564 goto return_exception;
1566 c->fieldscount = suck_u2(cb);
1567 c->fields = MNEW(fieldinfo, c->fieldscount);
1569 MZERO(c->fields, fieldinfo, c->fieldscount);
1571 for (i = 0; i < c->fieldscount; i++) {
1572 if (!field_load(cb, &(c->fields[i]), descpool))
1573 goto return_exception;
1576 RT_TIMING_GET_TIME(time_fields);
1580 if (!suck_check_classbuffer_size(cb, 2))
1581 goto return_exception;
1583 c->methodscount = suck_u2(cb);
1584 c->methods = MNEW(methodinfo, c->methodscount);
1586 MZERO(c->methods, methodinfo, c->methodscount);
1588 for (i = 0; i < c->methodscount; i++) {
1589 if (!method_load(cb, &(c->methods[i]), descpool))
1590 goto return_exception;
1593 RT_TIMING_GET_TIME(time_methods);
1595 /* create the class reference table */
1598 descriptor_pool_create_classrefs(descpool, &(c->classrefcount));
1600 RT_TIMING_GET_TIME(time_classrefs);
1602 /* allocate space for the parsed descriptors */
1604 descriptor_pool_alloc_parsed_descriptors(descpool);
1606 descriptor_pool_get_parsed_descriptors(descpool, &(c->parseddescsize));
1608 #if defined(ENABLE_STATISTICS)
1610 descriptor_pool_get_sizes(descpool, &classrefsize, &descsize);
1611 count_classref_len += classrefsize;
1612 count_parsed_desc_len += descsize;
1616 RT_TIMING_GET_TIME(time_descs);
1618 /* put the classrefs in the constant pool */
1619 for (i = 0; i < c->cpcount; i++) {
1620 if (c->cptags[i] == CONSTANT_Class) {
1621 utf *name = (utf *) c->cpinfos[i];
1622 c->cpinfos[i] = descriptor_pool_lookup_classref(descpool, name);
1626 /* set the super class reference */
1629 c->super.ref = descriptor_pool_lookup_classref(descpool, supername);
1631 goto return_exception;
1634 /* set the super interfaces references */
1636 for (i = 0; i < c->interfacescount; i++) {
1637 c->interfaces[i].ref =
1638 descriptor_pool_lookup_classref(descpool,
1639 (utf *) c->interfaces[i].any);
1640 if (!c->interfaces[i].ref)
1641 goto return_exception;
1644 RT_TIMING_GET_TIME(time_setrefs);
1646 /* parse field descriptors */
1648 for (i = 0; i < c->fieldscount; i++) {
1649 c->fields[i].parseddesc =
1650 descriptor_pool_parse_field_descriptor(descpool,
1651 c->fields[i].descriptor);
1652 if (!c->fields[i].parseddesc)
1653 goto return_exception;
1656 RT_TIMING_GET_TIME(time_parsefds);
1658 /* parse method descriptors */
1660 for (i = 0; i < c->methodscount; i++) {
1661 methodinfo *m = &c->methods[i];
1663 descriptor_pool_parse_method_descriptor(descpool, m->descriptor,
1664 m->flags, class_get_self_classref(m->class));
1666 goto return_exception;
1668 for (j = 0; j < m->rawexceptiontablelength; j++) {
1669 if (!m->rawexceptiontable[j].catchtype.any)
1671 if ((m->rawexceptiontable[j].catchtype.ref =
1672 descriptor_pool_lookup_classref(descpool,
1673 (utf *) m->rawexceptiontable[j].catchtype.any)) == NULL)
1674 goto return_exception;
1677 for (j = 0; j < m->thrownexceptionscount; j++) {
1678 if (!m->thrownexceptions[j].any)
1680 if ((m->thrownexceptions[j].ref = descriptor_pool_lookup_classref(descpool,
1681 (utf *) m->thrownexceptions[j].any)) == NULL)
1682 goto return_exception;
1686 RT_TIMING_GET_TIME(time_parsemds);
1688 /* parse the loaded descriptors */
1690 for (i = 0; i < c->cpcount; i++) {
1691 constant_FMIref *fmi;
1694 switch (c->cptags[i]) {
1695 case CONSTANT_Fieldref:
1696 fmi = (constant_FMIref *) c->cpinfos[i];
1697 fmi->parseddesc.fd =
1698 descriptor_pool_parse_field_descriptor(descpool,
1700 if (!fmi->parseddesc.fd)
1701 goto return_exception;
1702 index = fmi->p.index;
1704 (constant_classref *) class_getconstant(c, index,
1706 if (!fmi->p.classref)
1707 goto return_exception;
1709 case CONSTANT_Methodref:
1710 case CONSTANT_InterfaceMethodref:
1711 fmi = (constant_FMIref *) c->cpinfos[i];
1712 index = fmi->p.index;
1714 (constant_classref *) class_getconstant(c, index,
1716 if (!fmi->p.classref)
1717 goto return_exception;
1718 fmi->parseddesc.md =
1719 descriptor_pool_parse_method_descriptor(descpool,
1723 if (!fmi->parseddesc.md)
1724 goto return_exception;
1729 RT_TIMING_GET_TIME(time_parsecpool);
1731 #ifdef ENABLE_VERIFIER
1732 /* Check if all fields and methods can be uniquely
1733 * identified by (name,descriptor). */
1736 /* We use a hash table here to avoid making the
1737 * average case quadratic in # of methods, fields.
1739 static int shift = 0;
1741 u2 *next; /* for chaining colliding hash entries */
1747 /* Allocate hashtable */
1748 len = c->methodscount;
1749 if (len < c->fieldscount) len = c->fieldscount;
1751 hashtab = MNEW(u2,(hashlen + len));
1752 next = hashtab + hashlen;
1754 /* Determine bitshift (to get good hash values) */
1764 memset(hashtab, 0, sizeof(u2) * (hashlen + len));
1766 for (i = 0; i < c->fieldscount; ++i) {
1767 fieldinfo *fi = c->fields + i;
1769 /* It's ok if we lose bits here */
1770 index = ((((size_t) fi->name) +
1771 ((size_t) fi->descriptor)) >> shift) % hashlen;
1773 if ((old = hashtab[index])) {
1777 if (c->fields[old].name == fi->name &&
1778 c->fields[old].descriptor == fi->descriptor) {
1779 exceptions_throw_classformaterror(c, "Repetitive field name/signature");
1780 goto return_exception;
1782 } while ((old = next[old]));
1784 hashtab[index] = i + 1;
1788 memset(hashtab, 0, sizeof(u2) * (hashlen + hashlen/5));
1790 for (i = 0; i < c->methodscount; ++i) {
1791 methodinfo *mi = c->methods + i;
1793 /* It's ok if we lose bits here */
1794 index = ((((size_t) mi->name) +
1795 ((size_t) mi->descriptor)) >> shift) % hashlen;
1799 for (dbg=0;dbg<hashlen+hashlen/5;++dbg){
1800 printf("Hash[%d]:%d\n",dbg,hashtab[dbg]);
1804 if ((old = hashtab[index])) {
1808 if (c->methods[old].name == mi->name &&
1809 c->methods[old].descriptor == mi->descriptor) {
1810 exceptions_throw_classformaterror(c, "Repetitive method name/signature");
1811 goto return_exception;
1813 } while ((old = next[old]));
1815 hashtab[index] = i + 1;
1818 MFREE(hashtab, u2, (hashlen + len));
1820 #endif /* ENABLE_VERIFIER */
1822 RT_TIMING_GET_TIME(time_verify);
1824 #if defined(ENABLE_STATISTICS)
1826 size_classinfo += sizeof(classinfo*) * c->interfacescount;
1827 size_fieldinfo += sizeof(fieldinfo) * c->fieldscount;
1828 size_methodinfo += sizeof(methodinfo) * c->methodscount;
1832 /* load attribute structures */
1834 if (!class_load_attributes(cb))
1835 goto return_exception;
1837 /* Pre Java 1.5 version don't check this. This implementation is like
1838 Java 1.5 do it: for class file version 45.3 we don't check it, older
1839 versions are checked.
1842 if (((ma == 45) && (mi > 3)) || (ma > 45)) {
1843 /* check if all data has been read */
1844 s4 classdata_left = ((cb->data + cb->size) - cb->pos);
1846 if (classdata_left > 0) {
1847 exceptions_throw_classformaterror(c, "Extra bytes at the end of class file");
1848 goto return_exception;
1852 RT_TIMING_GET_TIME(time_attrs);
1854 /* release dump area */
1856 dump_release(dumpsize);
1858 /* revert loading state and class is loaded */
1860 c->state = (c->state & ~CLASS_LOADING) | CLASS_LOADED;
1862 #if defined(ENABLE_JVMTI)
1863 /* fire Class Prepare JVMTI event */
1866 jvmti_ClassLoadPrepare(true, c);
1869 #if !defined(NDEBUG)
1871 log_message_class("Loading done class: ", c);
1874 RT_TIMING_TIME_DIFF(time_start , time_checks , RT_TIMING_LOAD_CHECKS);
1875 RT_TIMING_TIME_DIFF(time_checks , time_ndpool , RT_TIMING_LOAD_NDPOOL);
1876 RT_TIMING_TIME_DIFF(time_ndpool , time_cpool , RT_TIMING_LOAD_CPOOL);
1877 RT_TIMING_TIME_DIFF(time_cpool , time_setup , RT_TIMING_LOAD_SETUP);
1878 RT_TIMING_TIME_DIFF(time_setup , time_fields , RT_TIMING_LOAD_FIELDS);
1879 RT_TIMING_TIME_DIFF(time_fields , time_methods , RT_TIMING_LOAD_METHODS);
1880 RT_TIMING_TIME_DIFF(time_methods , time_classrefs , RT_TIMING_LOAD_CLASSREFS);
1881 RT_TIMING_TIME_DIFF(time_classrefs , time_descs , RT_TIMING_LOAD_DESCS);
1882 RT_TIMING_TIME_DIFF(time_descs , time_setrefs , RT_TIMING_LOAD_SETREFS);
1883 RT_TIMING_TIME_DIFF(time_setrefs , time_parsefds , RT_TIMING_LOAD_PARSEFDS);
1884 RT_TIMING_TIME_DIFF(time_parsefds , time_parsemds , RT_TIMING_LOAD_PARSEMDS);
1885 RT_TIMING_TIME_DIFF(time_parsemds , time_parsecpool, RT_TIMING_LOAD_PARSECP);
1886 RT_TIMING_TIME_DIFF(time_parsecpool, time_verify , RT_TIMING_LOAD_VERIFY);
1887 RT_TIMING_TIME_DIFF(time_verify , time_attrs , RT_TIMING_LOAD_ATTRS);
1888 RT_TIMING_TIME_DIFF(time_start , time_attrs , RT_TIMING_LOAD_TOTAL);
1893 /* release dump area */
1895 dump_release(dumpsize);
1897 /* an exception has been thrown */
1903 /* load_newly_created_array ****************************************************
1905 Load a newly created array class.
1908 c....................the array class C has been loaded
1909 other classinfo......the array class was found in the class cache,
1911 NULL.................an exception has been thrown
1914 This is an internal function. Do not use it unless you know exactly
1917 Use one of the load_class_... functions for general array class loading.
1919 *******************************************************************************/
1921 classinfo *load_newly_created_array(classinfo *c, classloader *loader)
1923 classinfo *comp = NULL;
1925 methoddesc *clonedesc;
1926 constant_classref *classrefs;
1931 text = c->name->text;
1932 namelen = c->name->blength;
1934 /* Check array class name */
1936 if ((namelen < 2) || (text[0] != '[')) {
1937 exceptions_throw_classnotfoundexception(c->name);
1941 /* Check the element type */
1945 /* c is an array of arrays. We have to create the component class. */
1947 u = utf_new(text + 1, namelen - 1);
1949 comp = load_class_from_classloader(u, loader);
1954 assert(comp->state & CLASS_LOADED);
1956 /* the array's flags are that of the component class */
1957 c->flags = (comp->flags & ~ACC_INTERFACE) | ACC_FINAL | ACC_ABSTRACT;
1958 c->classloader = comp->classloader;
1962 /* c is an array of objects. */
1964 /* check for cases like `[L;' or `[L[I;' or `[Ljava.lang.Object' */
1965 if ((namelen < 4) || (text[2] == '[') || (text[namelen - 1] != ';')) {
1966 exceptions_throw_classnotfoundexception(c->name);
1970 u = utf_new(text + 2, namelen - 3);
1972 if (!(comp = load_class_from_classloader(u, loader)))
1975 assert(comp->state & CLASS_LOADED);
1977 /* the array's flags are that of the component class */
1978 c->flags = (comp->flags & ~ACC_INTERFACE) | ACC_FINAL | ACC_ABSTRACT;
1979 c->classloader = comp->classloader;
1983 /* c is an array of a primitive type */
1985 /* check for cases like `[II' and whether the character is a
1986 valid primitive type */
1988 if ((namelen > 2) || (primitive_class_get_by_char(text[1]) == NULL)) {
1989 exceptions_throw_classnotfoundexception(c->name);
1993 /* the accessibility of the array class is public (VM Spec 5.3.3) */
1994 c->flags = ACC_PUBLIC | ACC_FINAL | ACC_ABSTRACT;
1995 c->classloader = NULL;
1998 assert(class_java_lang_Object);
1999 #if defined(ENABLE_JAVASE)
2000 assert(class_java_lang_Cloneable);
2001 assert(class_java_io_Serializable);
2004 /* setup the array class */
2006 c->super.cls = class_java_lang_Object;
2008 #if defined(ENABLE_JAVASE)
2010 c->interfacescount = 2;
2011 c->interfaces = MNEW(classref_or_classinfo, 2);
2012 c->interfaces[0].cls = class_java_lang_Cloneable;
2013 c->interfaces[1].cls = class_java_io_Serializable;
2015 #elif defined(ENABLE_JAVAME_CLDC1_1)
2017 c->interfacescount = 0;
2018 c->interfaces = NULL;
2021 # error unknow Java configuration
2024 c->methodscount = 1;
2025 c->methods = MNEW(methodinfo, c->methodscount);
2026 MZERO(c->methods, methodinfo, c->methodscount);
2028 classrefs = MNEW(constant_classref, 2);
2029 CLASSREF_INIT(classrefs[0], c, c->name);
2030 CLASSREF_INIT(classrefs[1], c, utf_java_lang_Object);
2032 /* create descriptor for clone method */
2033 /* we need one paramslot which is reserved for the 'this' parameter */
2034 clonedesc = NEW(methoddesc);
2035 clonedesc->returntype.type = TYPE_ADR;
2036 clonedesc->returntype.classref = classrefs + 1;
2037 clonedesc->returntype.arraydim = 0;
2038 /* initialize params to "empty", add real params below in
2039 descriptor_params_from_paramtypes */
2040 clonedesc->paramcount = 0;
2041 clonedesc->paramslots = 0;
2042 clonedesc->paramtypes[0].classref = classrefs + 0;
2043 clonedesc->params = NULL;
2045 /* create methodinfo */
2048 MSET(clone, 0, methodinfo, 1);
2050 #if defined(ENABLE_THREADS)
2051 lock_init_object_lock(&clone->header);
2054 /* ATTENTION: if you delete the ACC_NATIVE below, set
2055 clone->maxlocals=1 (interpreter related) */
2057 clone->flags = ACC_PUBLIC | ACC_NATIVE;
2058 clone->name = utf_clone;
2059 clone->descriptor = utf_void__java_lang_Object;
2060 clone->parseddesc = clonedesc;
2063 /* parse the descriptor to get the register allocation */
2065 if (!descriptor_params_from_paramtypes(clonedesc, clone->flags))
2068 clone->code = codegen_generate_stub_native(clone, BUILTIN_clone);
2070 /* XXX: field: length? */
2072 /* array classes are not loaded from class files */
2074 c->state |= CLASS_LOADED;
2075 c->parseddescs = (u1 *) clonedesc;
2076 c->parseddescsize = sizeof(methodinfo);
2077 c->classrefs = classrefs;
2078 c->classrefcount = 1;
2080 /* insert class into the loaded class cache */
2081 /* XXX free classinfo if NULL returned? */
2083 return classcache_store(loader, c, true);
2087 /* loader_close ****************************************************************
2089 Frees all resources.
2091 *******************************************************************************/
2093 void loader_close(void)
2100 * These are local overrides for various environment variables in Emacs.
2101 * Please do not remove this and leave it at the end of the file, where
2102 * Emacs will automagically detect them.
2103 * ---------------------------------------------------------------------
2106 * indent-tabs-mode: t
2110 * vim:noexpandtab:sw=4:ts=4: