1 /* src/vm/loader.cpp - class loader functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 Copyright (C) 2009 Theobroma Systems Ltd.
7 This file is part of CACAO.
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2, or (at
12 your option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
35 #include "mm/dumpmemory.hpp"
36 #include "mm/memory.hpp"
38 #include "native/llni.h"
40 #include "threads/mutex.hpp"
42 #include "toolbox/hashtable.h"
43 #include "toolbox/logging.hpp"
45 #include "vm/jit/builtin.hpp"
46 #include "vm/classcache.hpp"
47 #include "vm/exceptions.hpp"
48 #include "vm/field.hpp"
49 #include "vm/global.h"
50 #include "vm/globals.hpp"
51 #include "vm/linker.hpp"
52 #include "vm/loader.hpp"
53 #include "vm/method.hpp"
54 #include "vm/options.h"
55 #include "vm/package.hpp"
56 #include "vm/primitive.hpp"
57 #include "vm/resolve.hpp"
58 #include "vm/rt-timing.h"
59 #include "vm/string.hpp"
60 #include "vm/suck.hpp"
64 #if defined(ENABLE_JAVASE)
65 # include "vm/annotation.hpp"
66 # include "vm/stackmap.h"
69 #if defined(ENABLE_STATISTICS)
70 # include "vm/statistics.h"
73 #if defined(ENABLE_ZLIB)
74 # include "vm/zip.hpp"
77 #include "vm/jit/stubs.hpp"
79 #if defined(ENABLE_JVMTI)
80 # include "native/jvmti/cacaodbg.h"
84 /* global variables ***********************************************************/
86 static hashtable *hashtable_classloader;
89 /* loader_preinit **************************************************************
91 Initializes the classpath list and loads classes required for the
94 NOTE: Exceptions thrown during VM initialization are caught in the
95 exception functions themselves.
97 *******************************************************************************/
99 void loader_preinit(void)
101 TRACESUBSYSTEMINITIALIZATION("loader_preinit");
103 #if defined(ENABLE_THREADS)
104 // Get current list of classpath entries.
105 SuckClasspath& suckclasspath = VM::get_current()->get_suckclasspath();
107 /* Initialize the monitor pointer for zip/jar file locking. */
109 for (SuckClasspath::iterator it = suckclasspath.begin(); it != suckclasspath.end(); it++) {
110 list_classpath_entry* lce = *it;
112 if (lce->type == CLASSPATH_ARCHIVE)
113 lce->mutex = new Mutex();
117 /* initialize classloader hashtable, 10 entries should be enough */
119 hashtable_classloader = NEW(hashtable);
120 hashtable_create(hashtable_classloader, 10);
122 /* Load the most basic classes. */
124 assert(VM::get_current()->is_initializing() == true);
126 class_java_lang_Object = load_class_bootstrap(utf_java_lang_Object);
128 #if defined(ENABLE_JAVASE)
129 class_java_lang_Cloneable = load_class_bootstrap(utf_java_lang_Cloneable);
130 class_java_io_Serializable = load_class_bootstrap(utf_java_io_Serializable);
135 /* loader_init *****************************************************************
137 Loads all classes required in the VM.
139 NOTE: Exceptions thrown during VM initialization are caught in the
140 exception functions themselves.
142 *******************************************************************************/
144 void loader_init(void)
146 TRACESUBSYSTEMINITIALIZATION("loader_init");
148 /* Load primitive-type wrapping classes. */
150 assert(VM::get_current()->is_initializing() == true);
152 #if defined(ENABLE_JAVASE)
153 class_java_lang_Void = load_class_bootstrap(utf_java_lang_Void);
156 class_java_lang_Boolean = load_class_bootstrap(utf_java_lang_Boolean);
157 class_java_lang_Byte = load_class_bootstrap(utf_java_lang_Byte);
158 class_java_lang_Character = load_class_bootstrap(utf_java_lang_Character);
159 class_java_lang_Short = load_class_bootstrap(utf_java_lang_Short);
160 class_java_lang_Integer = load_class_bootstrap(utf_java_lang_Integer);
161 class_java_lang_Long = load_class_bootstrap(utf_java_lang_Long);
162 class_java_lang_Float = load_class_bootstrap(utf_java_lang_Float);
163 class_java_lang_Double = load_class_bootstrap(utf_java_lang_Double);
165 /* Load important system classes. */
167 class_java_lang_Class = load_class_bootstrap(utf_java_lang_Class);
168 class_java_lang_String = load_class_bootstrap(utf_java_lang_String);
170 #if defined(ENABLE_JAVASE)
171 class_java_lang_ClassLoader =
172 load_class_bootstrap(utf_java_lang_ClassLoader);
174 class_java_lang_SecurityManager =
175 load_class_bootstrap(utf_java_lang_SecurityManager);
178 class_java_lang_System =
179 load_class_bootstrap(utf_new_char("java/lang/System"));
181 class_java_lang_Thread =
182 load_class_bootstrap(utf_new_char("java/lang/Thread"));
184 #if defined(ENABLE_JAVASE)
185 class_java_lang_ThreadGroup =
186 load_class_bootstrap(utf_java_lang_ThreadGroup);
189 class_java_lang_Throwable = load_class_bootstrap(utf_java_lang_Throwable);
191 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
192 class_java_lang_VMSystem =
193 load_class_bootstrap(utf_new_char("java/lang/VMSystem"));
195 class_java_lang_VMThread =
196 load_class_bootstrap(utf_new_char("java/lang/VMThread"));
198 class_java_lang_VMThrowable =
199 load_class_bootstrap(utf_new_char("java/lang/VMThrowable"));
202 /* Important system exceptions. */
204 class_java_lang_Exception = load_class_bootstrap(utf_java_lang_Exception);
206 class_java_lang_ClassNotFoundException =
207 load_class_bootstrap(utf_java_lang_ClassNotFoundException);
209 class_java_lang_RuntimeException =
210 load_class_bootstrap(utf_java_lang_RuntimeException);
212 /* Some classes which may be used often. */
214 #if defined(ENABLE_JAVASE)
215 class_java_lang_StackTraceElement = load_class_bootstrap(utf_java_lang_StackTraceElement);
217 class_java_lang_reflect_Constructor = load_class_bootstrap(utf_java_lang_reflect_Constructor);
218 class_java_lang_reflect_Field = load_class_bootstrap(utf_java_lang_reflect_Field);
219 class_java_lang_reflect_Method = load_class_bootstrap(utf_java_lang_reflect_Method);
221 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
222 class_java_lang_reflect_VMConstructor = load_class_bootstrap(utf_java_lang_reflect_VMConstructor);
223 class_java_lang_reflect_VMField = load_class_bootstrap(utf_java_lang_reflect_VMField);
224 class_java_lang_reflect_VMMethod = load_class_bootstrap(utf_java_lang_reflect_VMMethod);
227 class_java_security_PrivilegedAction = load_class_bootstrap(utf_new_char("java/security/PrivilegedAction"));
229 class_java_util_HashMap = load_class_bootstrap(utf_new_char("java/util/HashMap"));
230 class_java_util_Vector = load_class_bootstrap(utf_java_util_Vector);
232 # if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
233 class_sun_misc_Signal = load_class_bootstrap(utf_new_char("sun/misc/Signal"));
234 class_sun_reflect_MagicAccessorImpl = load_class_bootstrap(utf_new_char("sun/reflect/MagicAccessorImpl"));
237 arrayclass_java_lang_Object =
238 load_class_bootstrap(utf_new_char("[Ljava/lang/Object;"));
240 # if defined(ENABLE_ANNOTATIONS)
241 /* needed by annotation support */
242 class_sun_reflect_ConstantPool =
243 load_class_bootstrap(utf_new_char("sun/reflect/ConstantPool"));
245 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
246 /* needed by GNU Classpaths annotation support */
247 class_sun_reflect_annotation_AnnotationParser =
248 load_class_bootstrap(utf_new_char("sun/reflect/annotation/AnnotationParser"));
255 /* loader_hashtable_classloader_add ********************************************
257 Adds an entry to the classloader hashtable.
259 REMEMBER: Also use this to register native loaders!
261 *******************************************************************************/
263 classloader_t *loader_hashtable_classloader_add(java_handle_t *cl)
265 hashtable_classloader_entry *cle;
272 hashtable_classloader->mutex->lock();
276 /* key for entry is the hashcode of the classloader;
277 aligned to 16-byte boundaries */
279 key = heap_hashcode(LLNI_DIRECT(cl)) >> 4;
280 slot = key & (hashtable_classloader->size - 1);
281 cle = (hashtable_classloader_entry*) hashtable_classloader->ptr[slot];
283 /* search hashchain for existing entry */
286 if (cle->object == LLNI_DIRECT(cl))
294 /* if no classloader was found, we create a new entry here */
297 cle = NEW(hashtable_classloader_entry);
299 #if defined(ENABLE_GC_CACAO)
300 /* register the classloader object with the GC */
302 gc_reference_register(&(cle->object), GC_REFTYPE_CLASSLOADER);
307 cle->object = LLNI_DIRECT(cl);
311 /*#define LOADER_DEBUG_CLASSLOADER*/
312 #ifdef LOADER_DEBUG_CLASSLOADER
313 printf("CLASSLOADER: adding new classloader entry %p for %p: ", cle, cl);
314 class_print(LLNI_vftbl_direct(cl)->class);
319 /* insert entry into hashtable */
321 cle->hashlink = (hashtable_classloader_entry*) hashtable_classloader->ptr[slot];
322 hashtable_classloader->ptr[slot] = cle;
324 /* update number of entries */
326 hashtable_classloader->entries++;
329 hashtable_classloader->mutex->unlock();
331 #if defined(ENABLE_HANDLES)
339 /* loader_hashtable_classloader_find *******************************************
341 Find an entry in the classloader hashtable.
343 *******************************************************************************/
345 classloader_t *loader_hashtable_classloader_find(java_handle_t *cl)
347 hashtable_classloader_entry *cle;
356 /* key for entry is the hashcode of the classloader;
357 aligned to 16-byte boundaries */
359 key = heap_hashcode(LLNI_DIRECT(cl)) >> 4;
360 slot = key & (hashtable_classloader->size - 1);
361 cle = (hashtable_classloader_entry*) hashtable_classloader->ptr[slot];
363 /* search hashchain for existing entry */
366 if (cle->object == LLNI_DIRECT(cl))
372 #ifdef LOADER_DEBUG_CLASSLOADER
374 printf("CLASSLOADER: unable to find classloader entry for %p: ", cl);
375 class_print(LLNI_vftbl_direct(cl)->class);
383 #if defined(ENABLE_HANDLES)
391 /* loader_load_all_classes *****************************************************
393 Loads all classes specified in the BOOTCLASSPATH.
395 *******************************************************************************/
397 void loader_load_all_classes(void)
399 #if defined(ENABLE_ZLIB)
401 hashtable_zipfile_entry *htzfe;
405 // Get current list of classpath entries.
406 SuckClasspath& suckclasspath = VM::get_current()->get_suckclasspath();
408 for (SuckClasspath::iterator it = suckclasspath.begin(); it != suckclasspath.end(); it++) {
409 list_classpath_entry* lce = *it;
411 #if defined(ENABLE_ZLIB)
412 if (lce->type == CLASSPATH_ARCHIVE) {
413 /* get the classes hashtable */
417 for (uint32_t slot = 0; slot < ht->size; slot++) {
418 htzfe = (hashtable_zipfile_entry *) ht->ptr[slot];
420 for (; htzfe; htzfe = htzfe->hashlink) {
423 /* skip all entries in META-INF and .properties,
426 if (!strncmp(u->text, "META-INF", strlen("META-INF")) ||
427 strstr(u->text, ".properties") ||
428 strstr(u->text, ".png"))
431 /* load class from bootstrap classloader */
433 if (!load_class_bootstrap(u)) {
434 fprintf(stderr, "Error loading: ");
435 utf_fprint_printable_ascii_classname(stderr, u);
436 fprintf(stderr, "\n");
439 /* print out exception and cause */
441 exceptions_print_current_exception();
449 #if defined(ENABLE_ZLIB)
456 /* loader_skip_attribute_body **************************************************
458 Skips an attribute the attribute_name_index has already been read.
461 u2 attribute_name_index;
463 u1 info[attribute_length];
466 *******************************************************************************/
468 bool loader_skip_attribute_body(classbuffer *cb)
472 if (!suck_check_classbuffer_size(cb, 4))
475 attribute_length = suck_u4(cb);
477 if (!suck_check_classbuffer_size(cb, attribute_length))
480 suck_skip_nbytes(cb, attribute_length);
486 /* load_constantpool ***********************************************************
488 Loads the constantpool of a class, the entries are transformed into
489 a simpler format by resolving references (a detailed overview of
490 the compact structures can be found in global.h).
492 *******************************************************************************/
494 static bool load_constantpool(classbuffer *cb, descriptor_pool *descpool)
497 /* The following structures are used to save information which cannot be
498 processed during the first pass. After the complete constantpool has
499 been traversed the references can be resolved.
500 (only in specific order) */
502 /* CONSTANT_Class entries */
503 typedef struct forward_class {
504 struct forward_class *next;
509 /* CONSTANT_String */
510 typedef struct forward_string {
511 struct forward_string *next;
516 /* CONSTANT_NameAndType */
517 typedef struct forward_nameandtype {
518 struct forward_nameandtype *next;
522 } forward_nameandtype;
524 /* CONSTANT_Fieldref, CONSTANT_Methodref or CONSTANT_InterfaceMethodref */
525 typedef struct forward_fieldmethint {
526 struct forward_fieldmethint *next;
530 u2 nameandtype_index;
531 } forward_fieldmethint;
537 forward_class *forward_classes = NULL;
538 forward_string *forward_strings = NULL;
539 forward_nameandtype *forward_nameandtypes = NULL;
540 forward_fieldmethint *forward_fieldmethints = NULL;
544 forward_nameandtype *nfn;
545 forward_fieldmethint *nff;
553 /* number of entries in the constant_pool table plus one */
554 if (!suck_check_classbuffer_size(cb, 2))
557 cpcount = c->cpcount = suck_u2(cb);
559 /* allocate memory */
560 cptags = c->cptags = MNEW(u1, cpcount);
561 cpinfos = c->cpinfos = MNEW(void*, cpcount);
564 exceptions_throw_classformaterror(c, "Illegal constant pool size");
568 #if defined(ENABLE_STATISTICS)
570 count_const_pool_len += (sizeof(u1) + sizeof(void*)) * cpcount;
573 /* initialize constantpool */
574 for (idx = 0; idx < cpcount; idx++) {
575 cptags[idx] = CONSTANT_UNUSED;
580 /******* first pass *******/
581 /* entries which cannot be resolved now are written into
582 temporary structures and traversed again later */
585 while (idx < cpcount) {
588 /* get constant type */
589 if (!suck_check_classbuffer_size(cb, 1))
597 nfc = (forward_class*) DumpMemory::allocate(sizeof(forward_class));
599 nfc->next = forward_classes;
600 forward_classes = nfc;
602 nfc->thisindex = idx;
603 /* reference to CONSTANT_NameAndType */
604 if (!suck_check_classbuffer_size(cb, 2))
607 nfc->name_index = suck_u2(cb);
612 case CONSTANT_String:
614 nfs = (forward_string*) DumpMemory::allocate(sizeof(forward_string));
616 nfs->next = forward_strings;
617 forward_strings = nfs;
619 nfs->thisindex = idx;
621 /* reference to CONSTANT_Utf8_info with string characters */
622 if (!suck_check_classbuffer_size(cb, 2))
625 nfs->string_index = suck_u2(cb);
630 case CONSTANT_NameAndType:
632 nfn = (forward_nameandtype*) DumpMemory::allocate(sizeof(forward_nameandtype));
634 nfn->next = forward_nameandtypes;
635 forward_nameandtypes = nfn;
637 nfn->thisindex = idx;
639 if (!suck_check_classbuffer_size(cb, 2 + 2))
642 /* reference to CONSTANT_Utf8_info containing simple name */
643 nfn->name_index = suck_u2(cb);
645 /* reference to CONSTANT_Utf8_info containing field or method
647 nfn->sig_index = suck_u2(cb);
652 case CONSTANT_Fieldref:
653 case CONSTANT_Methodref:
654 case CONSTANT_InterfaceMethodref:
656 nff = (forward_fieldmethint*) DumpMemory::allocate(sizeof(forward_fieldmethint));
658 nff->next = forward_fieldmethints;
659 forward_fieldmethints = nff;
661 nff->thisindex = idx;
665 if (!suck_check_classbuffer_size(cb, 2 + 2))
668 /* class or interface type that contains the declaration of the
670 nff->class_index = suck_u2(cb);
672 /* name and descriptor of the field or method */
673 nff->nameandtype_index = suck_u2(cb);
678 case CONSTANT_Integer: {
679 constant_integer *ci = NEW(constant_integer);
681 #if defined(ENABLE_STATISTICS)
683 count_const_pool_len += sizeof(constant_integer);
686 if (!suck_check_classbuffer_size(cb, 4))
689 ci->value = suck_s4(cb);
690 cptags[idx] = CONSTANT_Integer;
697 case CONSTANT_Float: {
698 constant_float *cf = NEW(constant_float);
700 #if defined(ENABLE_STATISTICS)
702 count_const_pool_len += sizeof(constant_float);
705 if (!suck_check_classbuffer_size(cb, 4))
708 cf->value = suck_float(cb);
709 cptags[idx] = CONSTANT_Float;
716 case CONSTANT_Long: {
717 constant_long *cl = NEW(constant_long);
719 #if defined(ENABLE_STATISTICS)
721 count_const_pool_len += sizeof(constant_long);
724 if (!suck_check_classbuffer_size(cb, 8))
727 cl->value = suck_s8(cb);
728 cptags[idx] = CONSTANT_Long;
732 exceptions_throw_classformaterror(c, "Invalid constant pool entry");
738 case CONSTANT_Double: {
739 constant_double *cd = NEW(constant_double);
741 #if defined(ENABLE_STATISTICS)
743 count_const_pool_len += sizeof(constant_double);
746 if (!suck_check_classbuffer_size(cb, 8))
749 cd->value = suck_double(cb);
750 cptags[idx] = CONSTANT_Double;
754 exceptions_throw_classformaterror(c, "Invalid constant pool entry");
760 case CONSTANT_Utf8: {
763 /* number of bytes in the bytes array (not string-length) */
764 if (!suck_check_classbuffer_size(cb, 2))
767 length = suck_u2(cb);
768 cptags[idx] = CONSTANT_Utf8;
770 /* validate the string */
771 if (!suck_check_classbuffer_size(cb, length))
774 #ifdef ENABLE_VERIFIER
776 !is_valid_utf((char *) cb->pos, (char *) (cb->pos + length)))
778 exceptions_throw_classformaterror(c, "Invalid UTF-8 string");
781 #endif /* ENABLE_VERIFIER */
782 /* insert utf-string into the utf-symboltable */
783 cpinfos[idx] = utf_new((char *) cb->pos, length);
785 /* skip bytes of the string (buffer size check above) */
786 suck_skip_nbytes(cb, length);
792 exceptions_throw_classformaterror(c, "Illegal constant pool type");
798 /* resolve entries in temporary structures */
800 while (forward_classes) {
801 utf *name = (utf*) class_getconstant(c, forward_classes->name_index, CONSTANT_Utf8);
805 #ifdef ENABLE_VERIFIER
806 if (opt_verify && !is_valid_name_utf(name)) {
807 exceptions_throw_classformaterror(c, "Class reference with invalid name");
810 #endif /* ENABLE_VERIFIER */
812 /* add all class references to the descriptor_pool */
814 if (!descriptor_pool_add_class(descpool, name))
817 cptags[forward_classes->thisindex] = CONSTANT_Class;
819 /* the classref is created later */
820 cpinfos[forward_classes->thisindex] = name;
822 nfc = forward_classes;
823 forward_classes = forward_classes->next;
826 while (forward_strings) {
827 utf *text = (utf*) class_getconstant(c, forward_strings->string_index, CONSTANT_Utf8);
832 /* resolve utf-string */
833 cptags[forward_strings->thisindex] = CONSTANT_String;
834 cpinfos[forward_strings->thisindex] = text;
836 nfs = forward_strings;
837 forward_strings = forward_strings->next;
840 while (forward_nameandtypes) {
841 constant_nameandtype *cn = NEW(constant_nameandtype);
843 #if defined(ENABLE_STATISTICS)
845 count_const_pool_len += sizeof(constant_nameandtype);
848 /* resolve simple name and descriptor */
849 cn->name = (utf*) class_getconstant(c,
850 forward_nameandtypes->name_index,
855 cn->descriptor = (utf*) class_getconstant(c,
856 forward_nameandtypes->sig_index,
861 #ifdef ENABLE_VERIFIER
864 if (!is_valid_name_utf(cn->name)) {
865 exceptions_throw_classformaterror(c,
866 "Illegal Field name \"%s\"",
872 /* disallow referencing <clinit> among others */
873 if (cn->name->text[0] == '<' && cn->name != utf_init) {
874 exceptions_throw_classformaterror(c, "Illegal reference to special method");
878 #endif /* ENABLE_VERIFIER */
880 cptags[forward_nameandtypes->thisindex] = CONSTANT_NameAndType;
881 cpinfos[forward_nameandtypes->thisindex] = cn;
883 nfn = forward_nameandtypes;
884 forward_nameandtypes = forward_nameandtypes->next;
887 while (forward_fieldmethints) {
888 constant_nameandtype *nat;
889 constant_FMIref *fmi = NEW(constant_FMIref);
891 #if defined(ENABLE_STATISTICS)
893 count_const_pool_len += sizeof(constant_FMIref);
895 /* resolve simple name and descriptor */
897 nat = (constant_nameandtype*) class_getconstant(c,
898 forward_fieldmethints->nameandtype_index,
899 CONSTANT_NameAndType);
904 /* add all descriptors in {Field,Method}ref to the descriptor_pool */
906 if (!descriptor_pool_add(descpool, nat->descriptor, NULL))
909 /* the classref is created later */
911 fmi->p.index = forward_fieldmethints->class_index;
912 fmi->name = nat->name;
913 fmi->descriptor = nat->descriptor;
915 cptags[forward_fieldmethints->thisindex] = forward_fieldmethints->tag;
916 cpinfos[forward_fieldmethints->thisindex] = fmi;
918 nff = forward_fieldmethints;
919 forward_fieldmethints = forward_fieldmethints->next;
922 /* everything was ok */
928 /* loader_load_attribute_signature *********************************************
930 Signature_attribute {
931 u2 attribute_name_index;
936 *******************************************************************************/
938 #if defined(ENABLE_JAVASE)
939 bool loader_load_attribute_signature(classbuffer *cb, utf **signature)
949 /* check remaining bytecode */
951 if (!suck_check_classbuffer_size(cb, 4 + 2))
954 /* check attribute length */
956 attribute_length = suck_u4(cb);
958 if (attribute_length != 2) {
959 exceptions_throw_classformaterror(c, "Wrong size for VALUE attribute");
963 if (*signature != NULL) {
964 exceptions_throw_classformaterror(c, "Multiple Signature attributes");
970 signature_index = suck_u2(cb);
972 *signature = (utf*) class_getconstant(c, signature_index, CONSTANT_Utf8);
974 if (*signature == NULL)
979 #endif /* defined(ENABLE_JAVASE) */
982 /* load_class_from_sysloader ***************************************************
984 Load the class with the given name using the system class loader
987 name.............the classname
991 NULL if an exception has been thrown
993 *******************************************************************************/
995 classinfo *load_class_from_sysloader(utf *name)
1002 assert(class_java_lang_Object);
1003 assert(class_java_lang_ClassLoader);
1004 assert(class_java_lang_ClassLoader->state & CLASS_LINKED);
1006 m = class_resolveclassmethod(class_java_lang_ClassLoader,
1007 utf_getSystemClassLoader,
1008 utf_void__java_lang_ClassLoader,
1009 class_java_lang_Object,
1015 clo = vm_call_method(m, NULL);
1020 cl = loader_hashtable_classloader_add(clo);
1022 c = load_class_from_classloader(name, cl);
1028 /* load_class_from_classloader *************************************************
1030 Load the class with the given name using the given user-defined class loader.
1033 name.............the classname
1034 cl...............user-defined class loader
1037 the loaded class, or
1038 NULL if an exception has been thrown
1040 *******************************************************************************/
1042 classinfo *load_class_from_classloader(utf *name, classloader_t *cl)
1047 java_handle_t *string;
1048 #if defined(ENABLE_RT_TIMING)
1049 struct timespec time_start, time_lookup, time_prepare, time_java,
1053 RT_TIMING_GET_TIME(time_start);
1057 /* lookup if this class has already been loaded */
1059 c = classcache_lookup(cl, name);
1061 RT_TIMING_GET_TIME(time_lookup);
1062 RT_TIMING_TIME_DIFF(time_start,time_lookup,RT_TIMING_LOAD_CL_LOOKUP);
1067 /* if other class loader than bootstrap, call it */
1075 namelen = name->blength;
1077 /* handle array classes */
1078 if (text[0] == '[') {
1084 /* check for cases like `[L;' or `[L[I;' or `[Ljava.lang.Object' */
1085 if (namelen < 4 || text[2] == '[' || text[namelen - 1] != ';') {
1086 exceptions_throw_classnotfoundexception(name);
1090 u = utf_new(text + 2, namelen - 3);
1092 if (!(comp = load_class_from_classloader(u, cl)))
1095 /* create the array class */
1097 c = class_array_of(comp, false);
1099 tmpc = classcache_store(cl, c, true);
1102 /* exception, free the loaded class */
1103 c->state &= ~CLASS_LOADING;
1110 /* load the component class */
1112 u = utf_new(text + 1, namelen - 1);
1114 if (!(comp = load_class_from_classloader(u, cl)))
1117 /* create the array class */
1119 c = class_array_of(comp, false);
1121 tmpc = classcache_store(cl, c, true);
1124 /* exception, free the loaded class */
1125 c->state &= ~CLASS_LOADING;
1132 /* primitive array classes are loaded by the bootstrap loader */
1134 c = load_class_bootstrap(name);
1140 LLNI_class_get(cl, c);
1142 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1143 /* OpenJDK uses this internal function because it's
1146 lc = class_resolveclassmethod(c,
1147 utf_loadClassInternal,
1148 utf_java_lang_String__java_lang_Class,
1152 lc = class_resolveclassmethod(c,
1154 utf_java_lang_String__java_lang_Class,
1160 return false; /* exception */
1162 /* move return value into `o' and cast it afterwards to a classinfo* */
1164 string = javastring_new_slash_to_dot(name);
1166 RT_TIMING_GET_TIME(time_prepare);
1168 o = vm_call_method(lc, (java_handle_t *) cl, string);
1170 RT_TIMING_GET_TIME(time_java);
1172 c = LLNI_classinfo_unwrap(o);
1175 /* Store this class in the loaded class cache. If another
1176 class with the same (initloader,name) pair has been
1177 stored earlier it will be returned by classcache_store
1178 In this case classcache_store may not free the class
1179 because it has already been exposed to Java code which
1180 may have kept references to that class. */
1182 tmpc = classcache_store(cl, c, false);
1185 /* exception, free the loaded class */
1186 c->state &= ~CLASS_LOADING;
1193 // Expected behavior for the classloader is to throw an exception
1194 // and never return NULL. If the classloader shows a different
1195 // behavior, we are correcting it here (see PR126).
1196 if (exceptions_get_exception() == NULL) {
1197 #if !defined(NDEBUG)
1198 if (opt_PrintWarnings)
1199 log_message_utf("load_class_from_classloader: Correcting faulty classloader behavior (PR126) for ", name);
1201 exceptions_throw_classnotfoundexception(name);
1205 RT_TIMING_GET_TIME(time_cache);
1207 RT_TIMING_TIME_DIFF(time_lookup , time_prepare, RT_TIMING_LOAD_CL_PREPARE);
1208 RT_TIMING_TIME_DIFF(time_prepare, time_java , RT_TIMING_LOAD_CL_JAVA);
1209 RT_TIMING_TIME_DIFF(time_java , time_cache , RT_TIMING_LOAD_CL_CACHE);
1211 /* SUN compatible -verbose:class output */
1213 if (opt_verboseclass && (c != NULL) && (c->classloader == cl)) {
1215 utf_display_printable_ascii_classname(name);
1219 #if defined(ENABLE_JVMTI)
1220 /* fire Class Load JVMTI event */
1221 if (jvmti) jvmti_ClassLoadPrepare(false, c);
1228 c = load_class_bootstrap(name);
1234 /* load_class_bootstrap ********************************************************
1236 Load the class with the given name using the bootstrap class loader.
1239 name.............the classname
1242 loaded classinfo, or
1243 NULL if an exception has been thrown
1246 load_class_bootstrap is synchronized. It can be treated as an
1249 *******************************************************************************/
1251 classinfo *load_class_bootstrap(utf *name)
1256 #if defined(ENABLE_RT_TIMING)
1257 struct timespec time_start, time_lookup, time_array, time_suck,
1258 time_load, time_cache;
1261 RT_TIMING_GET_TIME(time_start);
1267 /* lookup if this class has already been loaded */
1269 r = classcache_lookup(NULL, name);
1272 RT_TIMING_GET_TIME(time_lookup);
1273 RT_TIMING_TIME_DIFF(time_start,time_lookup,RT_TIMING_LOAD_BOOT_LOOKUP);
1278 RT_TIMING_GET_TIME(time_lookup);
1279 RT_TIMING_TIME_DIFF(time_start,time_lookup,RT_TIMING_LOAD_BOOT_LOOKUP);
1281 /* create the classinfo */
1283 c = class_create_classinfo(name);
1285 /* handle array classes */
1287 if (name->text[0] == '[') {
1288 c = load_newly_created_array(c, NULL);
1293 assert(c->state & CLASS_LOADED);
1295 RT_TIMING_GET_TIME(time_array);
1296 RT_TIMING_TIME_DIFF(time_start,time_array,RT_TIMING_LOAD_BOOT_ARRAY);
1301 #if defined(ENABLE_STATISTICS)
1304 if (opt_getcompilingtime)
1305 compilingtime_stop();
1307 if (opt_getloadingtime)
1308 loadingtime_start();
1311 /* load classdata, throw exception on error */
1316 exceptions_throw_classnotfoundexception(name);
1320 RT_TIMING_GET_TIME(time_suck);
1322 /* load the class from the buffer */
1324 r = load_class_from_classbuffer(cb);
1326 RT_TIMING_GET_TIME(time_load);
1329 /* the class could not be loaded, free the classinfo struct */
1334 /* Store this class in the loaded class cache this step also
1335 checks the loading constraints. If the class has been
1336 loaded before, the earlier loaded class is returned. */
1338 classinfo *res = classcache_store(NULL, c, true);
1345 // Add the package name to the boot packages.
1346 Package::add(c->packagename);
1352 RT_TIMING_GET_TIME(time_cache);
1354 /* SUN compatible -verbose:class output */
1356 if (opt_verboseclass && r) {
1358 utf_display_printable_ascii_classname(name);
1359 printf(" from %s]\n", cb->path);
1366 #if defined(ENABLE_STATISTICS)
1369 if (opt_getloadingtime)
1372 if (opt_getcompilingtime)
1373 compilingtime_start();
1376 RT_TIMING_TIME_DIFF(time_lookup, time_suck , RT_TIMING_LOAD_BOOT_SUCK);
1377 RT_TIMING_TIME_DIFF(time_suck , time_load , RT_TIMING_LOAD_BOOT_LOAD);
1378 RT_TIMING_TIME_DIFF(time_load , time_cache, RT_TIMING_LOAD_BOOT_CACHE);
1379 RT_TIMING_TIME_DIFF(time_lookup, time_cache, RT_TIMING_LOAD_BOOT_TOTAL);
1385 /* load_class_from_classbuffer_intern ******************************************
1387 Loads a class from a classbuffer into a given classinfo structure.
1388 Super-classes are also loaded at this point and some verfication
1392 This function is NOT synchronized!
1394 *******************************************************************************/
1396 static bool load_class_from_classbuffer_intern(classbuffer *cb)
1402 utf **interfacesnames;
1404 constant_classref *cr;
1408 descriptor_pool *descpool;
1409 #if defined(ENABLE_STATISTICS)
1413 #if defined(ENABLE_RT_TIMING)
1414 struct timespec time_start, time_checks, time_ndpool, time_cpool,
1415 time_setup, time_fields, time_methods, time_classrefs,
1416 time_descs, time_setrefs, time_parsefds, time_parsemds,
1417 time_parsecpool, time_verify, time_attrs;
1420 // Create new dump memory area.
1423 RT_TIMING_GET_TIME(time_start);
1425 /* Get the classbuffer's class. */
1429 if (!suck_check_classbuffer_size(cb, 4 + 2 + 2))
1432 /* check signature */
1434 if (suck_u4(cb) != MAGIC) {
1435 exceptions_throw_classformaterror(c, "Bad magic number");
1444 if (!(ma < MAJOR_VERSION || (ma == MAJOR_VERSION && mi <= MINOR_VERSION))) {
1445 exceptions_throw_unsupportedclassversionerror(c, ma, mi);
1449 RT_TIMING_GET_TIME(time_checks);
1451 /* create a new descriptor pool */
1453 descpool = descriptor_pool_new(c);
1455 RT_TIMING_GET_TIME(time_ndpool);
1457 /* load the constant pool */
1459 if (!load_constantpool(cb, descpool))
1462 RT_TIMING_GET_TIME(time_cpool);
1466 if (!suck_check_classbuffer_size(cb, 2))
1469 /* We OR the flags here, as we set already some flags in
1470 class_create_classinfo. */
1472 c->flags |= suck_u2(cb);
1474 /* check ACC flags consistency */
1476 if (c->flags & ACC_INTERFACE) {
1477 if (!(c->flags & ACC_ABSTRACT)) {
1478 /* We work around this because interfaces in JDK 1.1 are
1479 * not declared abstract. */
1481 c->flags |= ACC_ABSTRACT;
1484 if (c->flags & ACC_FINAL) {
1485 exceptions_throw_classformaterror(c,
1486 "Illegal class modifiers: 0x%X",
1491 if (c->flags & ACC_SUPER) {
1492 c->flags &= ~ACC_SUPER; /* kjc seems to set this on interfaces */
1496 if ((c->flags & (ACC_ABSTRACT | ACC_FINAL)) == (ACC_ABSTRACT | ACC_FINAL)) {
1497 exceptions_throw_classformaterror(c,
1498 "Illegal class modifiers: 0x%X",
1503 if (!suck_check_classbuffer_size(cb, 2 + 2))
1508 index = suck_u2(cb);
1510 name = (utf *) class_getconstant(c, index, CONSTANT_Class);
1515 if (c->name == utf_not_named_yet) {
1516 /* we finally have a name for this class */
1518 class_set_packagename(c);
1520 else if (name != c->name) {
1521 exceptions_throw_noclassdeffounderror_wrong_name(c, name);
1525 /* Retrieve superclass. */
1529 index = suck_u2(cb);
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");
1542 supername = (utf *) class_getconstant(c, index, CONSTANT_Class);
1544 if (supername == NULL)
1547 /* java.lang.Object may not have a super class. */
1549 if (c->name == utf_java_lang_Object) {
1550 exceptions_throw_classformaterror(NULL, "java.lang.Object with superclass");
1554 /* Detect circularity. */
1556 if (supername == c->name) {
1557 exceptions_throw_classcircularityerror(c);
1561 /* Interfaces must have java.lang.Object as super class. */
1563 if ((c->flags & ACC_INTERFACE) && (supername != utf_java_lang_Object)) {
1564 exceptions_throw_classformaterror(c, "Interfaces must have java.lang.Object as superclass");
1569 /* Parse the super interfaces. */
1571 if (!suck_check_classbuffer_size(cb, 2))
1574 c->interfacescount = suck_u2(cb);
1576 if (!suck_check_classbuffer_size(cb, 2 * c->interfacescount))
1579 c->interfaces = MNEW(classinfo*, c->interfacescount);
1581 /* Get the names of the super interfaces. */
1583 interfacesnames = (utf**) DumpMemory::allocate(sizeof(utf*) * c->interfacescount);
1585 for (int32_t i = 0; i < c->interfacescount; i++) {
1586 index = suck_u2(cb);
1588 u = (utf *) class_getconstant(c, index, CONSTANT_Class);
1593 interfacesnames[i] = u;
1596 RT_TIMING_GET_TIME(time_setup);
1600 if (!suck_check_classbuffer_size(cb, 2))
1603 c->fieldscount = suck_u2(cb);
1604 c->fields = MNEW(fieldinfo, c->fieldscount);
1606 MZERO(c->fields, fieldinfo, c->fieldscount);
1608 for (int32_t i = 0; i < c->fieldscount; i++) {
1609 if (!field_load(cb, &(c->fields[i]), descpool))
1613 RT_TIMING_GET_TIME(time_fields);
1615 /* Parse methods. */
1617 if (!suck_check_classbuffer_size(cb, 2))
1620 c->methodscount = suck_u2(cb);
1621 c->methods = MNEW(methodinfo, c->methodscount);
1623 MZERO(c->methods, methodinfo, c->methodscount);
1625 for (int32_t i = 0; i < c->methodscount; i++) {
1626 if (!method_load(cb, &(c->methods[i]), descpool))
1630 RT_TIMING_GET_TIME(time_methods);
1632 /* create the class reference table */
1635 descriptor_pool_create_classrefs(descpool, &(c->classrefcount));
1637 RT_TIMING_GET_TIME(time_classrefs);
1639 /* allocate space for the parsed descriptors */
1641 descriptor_pool_alloc_parsed_descriptors(descpool);
1642 c->parseddescs = (u1*) descriptor_pool_get_parsed_descriptors(descpool, &(c->parseddescsize));
1644 #if defined(ENABLE_STATISTICS)
1646 descriptor_pool_get_sizes(descpool, &classrefsize, &descsize);
1647 count_classref_len += classrefsize;
1648 count_parsed_desc_len += descsize;
1652 RT_TIMING_GET_TIME(time_descs);
1654 /* put the classrefs in the constant pool */
1656 for (int32_t i = 0; i < c->cpcount; i++) {
1657 if (c->cptags[i] == CONSTANT_Class) {
1658 utf *name = (utf *) c->cpinfos[i];
1659 c->cpinfos[i] = descriptor_pool_lookup_classref(descpool, name);
1663 /* Resolve the super class. */
1665 if (supername != NULL) {
1666 cr = descriptor_pool_lookup_classref(descpool, supername);
1671 /* XXX This should be done better. */
1672 tc = resolve_classref_or_classinfo_eager(CLASSREF_OR_CLASSINFO(cr), false);
1675 resolve_handle_pending_exception(true);
1679 /* Interfaces are not allowed as super classes. */
1681 if (tc->flags & ACC_INTERFACE) {
1682 exceptions_throw_incompatibleclasschangeerror(c, "class %s has interface %s as super class");
1686 /* Don't allow extending final classes */
1688 if (tc->flags & ACC_FINAL) {
1689 exceptions_throw_verifyerror(NULL,
1690 "Cannot inherit from final class");
1694 /* Store the super class. */
1699 /* Resolve the super interfaces. */
1701 for (int32_t i = 0; i < c->interfacescount; i++) {
1702 u = interfacesnames[i];
1703 cr = descriptor_pool_lookup_classref(descpool, u);
1708 /* XXX This should be done better. */
1709 tc = resolve_classref_or_classinfo_eager(CLASSREF_OR_CLASSINFO(cr), false);
1712 resolve_handle_pending_exception(true);
1716 /* Detect circularity. */
1719 exceptions_throw_classcircularityerror(c);
1723 if (!(tc->flags & ACC_INTERFACE)) {
1724 exceptions_throw_incompatibleclasschangeerror(tc,
1725 "Implementing class");
1729 /* Store the super interface. */
1731 c->interfaces[i] = tc;
1734 RT_TIMING_GET_TIME(time_setrefs);
1736 /* Parse the field descriptors. */
1738 for (int32_t i = 0; i < c->fieldscount; i++) {
1739 c->fields[i].parseddesc =
1740 descriptor_pool_parse_field_descriptor(descpool,
1741 c->fields[i].descriptor);
1742 if (!c->fields[i].parseddesc)
1746 RT_TIMING_GET_TIME(time_parsefds);
1748 /* parse method descriptors */
1750 for (int32_t i = 0; i < c->methodscount; i++) {
1751 methodinfo *m = &c->methods[i];
1753 descriptor_pool_parse_method_descriptor(descpool, m->descriptor,
1754 m->flags, class_get_self_classref(m->clazz));
1758 for (int32_t j = 0; j < m->rawexceptiontablelength; j++) {
1759 if (!m->rawexceptiontable[j].catchtype.any)
1762 if ((m->rawexceptiontable[j].catchtype.ref =
1763 descriptor_pool_lookup_classref(descpool,
1764 (utf *) m->rawexceptiontable[j].catchtype.any)) == NULL)
1768 for (int32_t j = 0; j < m->thrownexceptionscount; j++) {
1769 if (!m->thrownexceptions[j].any)
1772 if ((m->thrownexceptions[j].ref = descriptor_pool_lookup_classref(descpool,
1773 (utf *) m->thrownexceptions[j].any)) == NULL)
1778 RT_TIMING_GET_TIME(time_parsemds);
1780 /* parse the loaded descriptors */
1782 for (int32_t i = 0; i < c->cpcount; i++) {
1783 constant_FMIref *fmi;
1786 switch (c->cptags[i]) {
1787 case CONSTANT_Fieldref:
1788 fmi = (constant_FMIref *) c->cpinfos[i];
1789 fmi->parseddesc.fd =
1790 descriptor_pool_parse_field_descriptor(descpool,
1792 if (!fmi->parseddesc.fd)
1795 index = fmi->p.index;
1797 (constant_classref *) class_getconstant(c, index,
1799 if (!fmi->p.classref)
1802 case CONSTANT_Methodref:
1803 case CONSTANT_InterfaceMethodref:
1804 fmi = (constant_FMIref *) c->cpinfos[i];
1805 index = fmi->p.index;
1807 (constant_classref *) class_getconstant(c, index,
1809 if (!fmi->p.classref)
1811 fmi->parseddesc.md =
1812 descriptor_pool_parse_method_descriptor(descpool,
1816 if (!fmi->parseddesc.md)
1822 RT_TIMING_GET_TIME(time_parsecpool);
1824 #ifdef ENABLE_VERIFIER
1825 /* Check if all fields and methods can be uniquely
1826 * identified by (name,descriptor). */
1829 /* We use a hash table here to avoid making the
1830 * average case quadratic in # of methods, fields.
1832 static int shift = 0;
1834 u2 *next; /* for chaining colliding hash entries */
1840 /* Allocate hashtable */
1841 len = c->methodscount;
1842 if (len < c->fieldscount) len = c->fieldscount;
1844 hashtab = MNEW(u2,(hashlen + len));
1845 next = hashtab + hashlen;
1847 /* Determine bitshift (to get good hash values) */
1857 memset(hashtab, 0, sizeof(u2) * (hashlen + len));
1859 for (int32_t i = 0; i < c->fieldscount; ++i) {
1860 fieldinfo *fi = c->fields + i;
1862 /* It's ok if we lose bits here */
1863 index = ((((size_t) fi->name) +
1864 ((size_t) fi->descriptor)) >> shift) % hashlen;
1866 if ((old = hashtab[index])) {
1870 if (c->fields[old].name == fi->name &&
1871 c->fields[old].descriptor == fi->descriptor) {
1872 exceptions_throw_classformaterror(c, "Repetitive field name/signature");
1875 } while ((old = next[old]));
1877 hashtab[index] = i + 1;
1881 memset(hashtab, 0, sizeof(u2) * (hashlen + hashlen/5));
1883 for (int32_t i = 0; i < c->methodscount; ++i) {
1884 methodinfo *mi = c->methods + i;
1886 /* It's ok if we lose bits here */
1887 index = ((((size_t) mi->name) +
1888 ((size_t) mi->descriptor)) >> shift) % hashlen;
1890 if ((old = hashtab[index])) {
1894 if (c->methods[old].name == mi->name &&
1895 c->methods[old].descriptor == mi->descriptor) {
1896 exceptions_throw_classformaterror(c, "Repetitive method name/signature");
1899 } while ((old = next[old]));
1901 hashtab[index] = i + 1;
1904 MFREE(hashtab, u2, (hashlen + len));
1906 #endif /* ENABLE_VERIFIER */
1908 RT_TIMING_GET_TIME(time_verify);
1910 #if defined(ENABLE_STATISTICS)
1912 size_classinfo += sizeof(classinfo*) * c->interfacescount;
1913 size_fieldinfo += sizeof(fieldinfo) * c->fieldscount;
1914 size_methodinfo += sizeof(methodinfo) * c->methodscount;
1918 /* load attribute structures */
1920 if (!class_load_attributes(cb))
1923 /* Pre Java 1.5 version don't check this. This implementation is
1924 like Java 1.5 do it: for class file version 45.3 we don't check
1925 it, older versions are checked. */
1927 if (((ma == 45) && (mi > 3)) || (ma > 45)) {
1928 /* check if all data has been read */
1929 s4 classdata_left = ((cb->data + cb->size) - cb->pos);
1931 if (classdata_left > 0) {
1932 exceptions_throw_classformaterror(c, "Extra bytes at the end of class file");
1937 RT_TIMING_GET_TIME(time_attrs);
1939 RT_TIMING_TIME_DIFF(time_start , time_checks , RT_TIMING_LOAD_CHECKS);
1940 RT_TIMING_TIME_DIFF(time_checks , time_ndpool , RT_TIMING_LOAD_NDPOOL);
1941 RT_TIMING_TIME_DIFF(time_ndpool , time_cpool , RT_TIMING_LOAD_CPOOL);
1942 RT_TIMING_TIME_DIFF(time_cpool , time_setup , RT_TIMING_LOAD_SETUP);
1943 RT_TIMING_TIME_DIFF(time_setup , time_fields , RT_TIMING_LOAD_FIELDS);
1944 RT_TIMING_TIME_DIFF(time_fields , time_methods , RT_TIMING_LOAD_METHODS);
1945 RT_TIMING_TIME_DIFF(time_methods , time_classrefs , RT_TIMING_LOAD_CLASSREFS);
1946 RT_TIMING_TIME_DIFF(time_classrefs , time_descs , RT_TIMING_LOAD_DESCS);
1947 RT_TIMING_TIME_DIFF(time_descs , time_setrefs , RT_TIMING_LOAD_SETREFS);
1948 RT_TIMING_TIME_DIFF(time_setrefs , time_parsefds , RT_TIMING_LOAD_PARSEFDS);
1949 RT_TIMING_TIME_DIFF(time_parsefds , time_parsemds , RT_TIMING_LOAD_PARSEMDS);
1950 RT_TIMING_TIME_DIFF(time_parsemds , time_parsecpool, RT_TIMING_LOAD_PARSECP);
1951 RT_TIMING_TIME_DIFF(time_parsecpool, time_verify , RT_TIMING_LOAD_VERIFY);
1952 RT_TIMING_TIME_DIFF(time_verify , time_attrs , RT_TIMING_LOAD_ATTRS);
1953 RT_TIMING_TIME_DIFF(time_start , time_attrs , RT_TIMING_LOAD_TOTAL);
1959 /* load_class_from_classbuffer *************************************************
1961 Convenience wrapper for load_class_from_classbuffer.
1964 This function is NOT synchronized!
1966 *******************************************************************************/
1968 classinfo *load_class_from_classbuffer(classbuffer *cb)
1973 /* Get the classbuffer's class. */
1977 /* Check if the class is already loaded. */
1979 if (c->state & CLASS_LOADED)
1982 #if defined(ENABLE_STATISTICS)
1984 count_class_loads++;
1987 #if !defined(NDEBUG)
1989 log_message_class("Loading class: ", c);
1992 /* Class is currently loading. */
1994 c->state |= CLASS_LOADING;
1996 /* Parse the classbuffer. */
1998 result = load_class_from_classbuffer_intern(cb);
2000 /* An error occurred. */
2002 if (result == false) {
2003 /* Revert loading state. */
2005 c->state = (c->state & ~CLASS_LOADING);
2010 /* Revert loading state and set loaded. */
2012 c->state = (c->state & ~CLASS_LOADING) | CLASS_LOADED;
2014 #if defined(ENABLE_JVMTI)
2015 /* fire Class Prepare JVMTI event */
2018 jvmti_ClassLoadPrepare(true, c);
2021 #if !defined(NDEBUG)
2023 log_message_class("Loading done class: ", c);
2030 /* load_newly_created_array ****************************************************
2032 Load a newly created array class.
2035 c....................the array class C has been loaded
2036 other classinfo......the array class was found in the class cache,
2038 NULL.................an exception has been thrown
2041 This is an internal function. Do not use it unless you know exactly
2044 Use one of the load_class_... functions for general array class loading.
2046 *******************************************************************************/
2048 classinfo *load_newly_created_array(classinfo *c, classloader_t *loader)
2050 classinfo *comp = NULL;
2052 methoddesc *clonedesc;
2053 constant_classref *classrefs;
2058 text = c->name->text;
2059 namelen = c->name->blength;
2061 /* Check array class name */
2063 if ((namelen < 2) || (text[0] != '[')) {
2064 exceptions_throw_classnotfoundexception(c->name);
2068 /* Check the element type */
2072 /* c is an array of arrays. We have to create the component class. */
2074 u = utf_new(text + 1, namelen - 1);
2076 comp = load_class_from_classloader(u, loader);
2081 assert(comp->state & CLASS_LOADED);
2083 /* the array's flags are that of the component class */
2084 c->flags = (comp->flags & ~ACC_INTERFACE) | ACC_FINAL | ACC_ABSTRACT;
2085 c->classloader = comp->classloader;
2089 /* c is an array of objects. */
2091 /* check for cases like `[L;' or `[L[I;' or `[Ljava.lang.Object' */
2092 if ((namelen < 4) || (text[2] == '[') || (text[namelen - 1] != ';')) {
2093 exceptions_throw_classnotfoundexception(c->name);
2097 u = utf_new(text + 2, namelen - 3);
2099 if (!(comp = load_class_from_classloader(u, loader)))
2102 assert(comp->state & CLASS_LOADED);
2104 /* the array's flags are that of the component class */
2105 c->flags = (comp->flags & ~ACC_INTERFACE) | ACC_FINAL | ACC_ABSTRACT;
2106 c->classloader = comp->classloader;
2110 /* c is an array of a primitive type */
2112 /* check for cases like `[II' and whether the character is a
2113 valid primitive type */
2115 if ((namelen > 2) || (Primitive::get_class_by_char(text[1]) == NULL)) {
2116 exceptions_throw_classnotfoundexception(c->name);
2120 /* the accessibility of the array class is public (VM Spec 5.3.3) */
2121 c->flags = ACC_PUBLIC | ACC_FINAL | ACC_ABSTRACT;
2122 c->classloader = NULL;
2125 assert(class_java_lang_Object);
2126 #if defined(ENABLE_JAVASE)
2127 assert(class_java_lang_Cloneable);
2128 assert(class_java_io_Serializable);
2131 /* Setup the array class. */
2133 c->super = class_java_lang_Object;
2135 #if defined(ENABLE_JAVASE)
2137 c->interfacescount = 2;
2138 c->interfaces = MNEW(classinfo*, 2);
2139 c->interfaces[0] = class_java_lang_Cloneable;
2140 c->interfaces[1] = class_java_io_Serializable;
2142 #elif defined(ENABLE_JAVAME_CLDC1_1)
2144 c->interfacescount = 0;
2145 c->interfaces = NULL;
2148 # error unknow Java configuration
2151 c->methodscount = 1;
2152 c->methods = MNEW(methodinfo, c->methodscount);
2154 MZERO(c->methods, methodinfo, c->methodscount);
2156 classrefs = MNEW(constant_classref, 2);
2158 CLASSREF_INIT(classrefs[0], c, c->name);
2159 CLASSREF_INIT(classrefs[1], c, utf_java_lang_Object);
2161 /* create descriptor for clone method */
2162 /* we need one paramslot which is reserved for the 'this' parameter */
2163 clonedesc = NEW(methoddesc);
2164 clonedesc->returntype.type = TYPE_ADR;
2165 clonedesc->returntype.classref = classrefs + 1;
2166 clonedesc->returntype.arraydim = 0;
2167 /* initialize params to "empty", add real params below in
2168 descriptor_params_from_paramtypes */
2169 clonedesc->paramcount = 0;
2170 clonedesc->paramslots = 0;
2171 clonedesc->paramtypes[0].classref = classrefs + 0;
2172 clonedesc->params = NULL;
2174 /* create methodinfo */
2177 MSET(clone, 0, methodinfo, 1);
2179 /* ATTENTION: if you delete the ACC_NATIVE below, set
2180 clone->maxlocals=1 (interpreter related) */
2182 clone->mutex = new Mutex();
2183 clone->flags = ACC_PUBLIC | ACC_NATIVE;
2184 clone->name = utf_clone;
2185 clone->descriptor = utf_void__java_lang_Object;
2186 clone->parseddesc = clonedesc;
2189 /* parse the descriptor to get the register allocation */
2191 if (!descriptor_params_from_paramtypes(clonedesc, clone->flags))
2194 clone->code = NativeStub::generate(clone, BUILTIN_clone);
2196 /* XXX: field: length? */
2198 /* array classes are not loaded from class files */
2200 c->state |= CLASS_LOADED;
2201 c->parseddescs = (u1 *) clonedesc;
2202 c->parseddescsize = sizeof(methodinfo);
2203 c->classrefs = classrefs;
2204 c->classrefcount = 1;
2206 /* insert class into the loaded class cache */
2207 /* XXX free classinfo if NULL returned? */
2209 return classcache_store(loader, c, true);
2213 /* loader_close ****************************************************************
2215 Frees all resources.
2217 *******************************************************************************/
2219 void loader_close(void)
2226 * These are local overrides for various environment variables in Emacs.
2227 * Please do not remove this and leave it at the end of the file, where
2228 * Emacs will automagically detect them.
2229 * ---------------------------------------------------------------------
2232 * indent-tabs-mode: t
2236 * vim:noexpandtab:sw=4:ts=4: