1 /* src/vm/class.c - class related functions
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Reinhard Grafl
33 $Id: class.c 3859 2005-12-03 13:00:28Z twisti $
43 #include "mm/memory.h"
45 #if defined(USE_THREADS)
46 # if defined(NATIVE_THREADS)
47 # include "threads/native/threads.h"
49 # include "threads/green/threads.h"
50 # include "threads/green/locks.h"
54 #include "toolbox/logging.h"
56 #include "vm/classcache.h"
57 #include "vm/exceptions.h"
58 #include "vm/global.h"
59 #include "vm/loader.h"
60 #include "vm/options.h"
61 #include "vm/resolve.h"
62 #include "vm/statistics.h"
63 #include "vm/stringlocal.h"
67 /******************************************************************************/
69 /******************************************************************************/
76 #define CLASS_ASSERT(cond) assert(cond)
78 #define CLASS_ASSERT(cond)
82 /* global variables ***********************************************************/
84 list unlinkedclasses; /* this is only used for eager class */
88 /* frequently used classes ****************************************************/
90 /* important system classes */
92 classinfo *class_java_lang_Object = NULL;
93 classinfo *class_java_lang_Class = NULL;
94 classinfo *class_java_lang_ClassLoader = NULL;
95 classinfo *class_java_lang_Cloneable = NULL;
96 classinfo *class_java_lang_SecurityManager = NULL;
97 classinfo *class_java_lang_String = NULL;
98 classinfo *class_java_lang_System = NULL;
99 classinfo *class_java_lang_Thread = NULL;
100 classinfo *class_java_lang_ThreadGroup = NULL;
101 classinfo *class_java_lang_VMThread = NULL;
102 classinfo *class_java_io_Serializable = NULL;
105 /* system exception classes required in cacao */
107 classinfo *class_java_lang_Throwable = NULL;
108 classinfo *class_java_lang_VMThrowable = NULL;
109 classinfo *class_java_lang_Error = NULL;
110 classinfo *class_java_lang_NoClassDefFoundError = NULL;
111 classinfo *class_java_lang_LinkageError = NULL;
112 classinfo *class_java_lang_NoSuchMethodError = NULL;
113 classinfo *class_java_lang_OutOfMemoryError = NULL;
115 classinfo *class_java_lang_Exception = NULL;
116 classinfo *class_java_lang_ClassNotFoundException = NULL;
117 classinfo *class_java_lang_IllegalArgumentException = NULL;
118 classinfo *class_java_lang_IllegalMonitorStateException = NULL;
120 classinfo *class_java_lang_Void = NULL;
121 classinfo *class_java_lang_Boolean = NULL;
122 classinfo *class_java_lang_Byte = NULL;
123 classinfo *class_java_lang_Character = NULL;
124 classinfo *class_java_lang_Short = NULL;
125 classinfo *class_java_lang_Integer = NULL;
126 classinfo *class_java_lang_Long = NULL;
127 classinfo *class_java_lang_Float = NULL;
128 classinfo *class_java_lang_Double = NULL;
131 /* some runtime exception */
133 classinfo *class_java_lang_NullPointerException = NULL;
136 /* some classes which may be used more often */
138 classinfo *class_java_lang_StackTraceElement = NULL;
139 classinfo *class_java_lang_reflect_Constructor = NULL;
140 classinfo *class_java_lang_reflect_Field = NULL;
141 classinfo *class_java_lang_reflect_Method = NULL;
142 classinfo *class_java_security_PrivilegedAction = NULL;
143 classinfo *class_java_util_Vector = NULL;
145 classinfo *arrayclass_java_lang_Object = NULL;
148 /* pseudo classes for the typechecker */
150 classinfo *pseudo_class_Arraystub = NULL;
151 classinfo *pseudo_class_Null = NULL;
152 classinfo *pseudo_class_New = NULL;
155 /* class_set_packagename *******************************************************
157 Derive the package name from the class name and store it in the struct.
159 *******************************************************************************/
161 void class_set_packagename(classinfo *c)
163 char *p = UTF_END(c->name) - 1;
164 char *start = c->name->text;
166 /* set the package name */
167 /* classes in the unnamed package keep packagename == NULL */
169 if (c->name->text[0] == '[') {
170 /* set packagename of arrays to the element's package */
172 for (; *start == '['; start++);
174 /* skip the 'L' in arrays of references */
178 for (; (p > start) && (*p != '/'); --p);
180 c->packagename = utf_new(start, p - start);
183 for (; (p > start) && (*p != '/'); --p);
185 c->packagename = utf_new(start, p - start);
190 /* class_create_classinfo ******************************************************
192 Create a new classinfo struct. The class name is set to the given utf *,
193 most other fields are initialized to zero.
195 Note: classname may be NULL. In this case a not-yet-named classinfo is
196 created. The name must be filled in later and class_set_packagename
197 must be called after that.
199 *******************************************************************************/
201 classinfo *class_create_classinfo(utf *classname)
205 #if defined(STATISTICS)
207 count_class_infos += sizeof(classinfo);
210 /* we use a safe name for temporarily unnamed classes */
212 classname = utf_not_named_yet;
215 log_message_utf("Creating class: ", classname);
217 /* GCNEW_UNCOLLECTABLE clears the allocated memory */
219 c = GCNEW_UNCOLLECTABLE(classinfo, 1);
220 /*c=NEW(classinfo);*/
223 /* set the header.vftbl of all loaded classes to the one of
224 java.lang.Class, so Java code can use a class as object */
226 if (class_java_lang_Class)
227 if (class_java_lang_Class->vftbl)
228 c->object.header.vftbl = class_java_lang_Class->vftbl;
230 if (classname != utf_not_named_yet)
231 class_set_packagename(c);
233 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
234 initObjectLock(&c->object.header);
241 /* class_postset_header_vftbl **************************************************
243 Set the header.vftbl of all classes created before java.lang.Class
244 was linked. This is necessary that Java code can use a class as
247 *******************************************************************************/
249 void class_postset_header_vftbl(void)
253 classcache_name_entry *nmen;
254 classcache_class_entry *clsen;
256 assert(class_java_lang_Class);
258 for (slot = 0; slot < hashtable_classcache.size; slot++) {
259 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
261 for (; nmen; nmen = nmen->hashlink) {
262 /* iterate over all class entries */
264 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
267 /* now set the the vftbl */
269 if (c->object.header.vftbl == NULL)
270 c->object.header.vftbl = class_java_lang_Class->vftbl;
277 /* class_freepool **************************************************************
279 Frees all resources used by this classes Constant Pool.
281 *******************************************************************************/
283 static void class_freecpool(classinfo *c)
289 if (c->cptags && c->cpinfos) {
290 for (idx = 0; idx < c->cpcount; idx++) {
291 tag = c->cptags[idx];
292 info = c->cpinfos[idx];
296 case CONSTANT_Fieldref:
297 case CONSTANT_Methodref:
298 case CONSTANT_InterfaceMethodref:
299 FREE(info, constant_FMIref);
301 case CONSTANT_Integer:
302 FREE(info, constant_integer);
305 FREE(info, constant_float);
308 FREE(info, constant_long);
310 case CONSTANT_Double:
311 FREE(info, constant_double);
313 case CONSTANT_NameAndType:
314 FREE(info, constant_nameandtype);
322 MFREE(c->cptags, u1, c->cpcount);
325 MFREE(c->cpinfos, voidptr, c->cpcount);
329 /* class_getconstant ***********************************************************
331 Retrieves the value at position 'pos' of the constantpool of a
332 class. If the type of the value is other than 'ctype', an error is
335 *******************************************************************************/
337 voidptr class_getconstant(classinfo *c, u4 pos, u4 ctype)
339 /* check index and type of constantpool entry */
340 /* (pos == 0 is caught by type comparison) */
342 if (pos >= c->cpcount || c->cptags[pos] != ctype) {
343 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
347 return c->cpinfos[pos];
351 /* innerclass_getconstant ******************************************************
353 Like class_getconstant, but if cptags is ZERO, null is returned.
355 *******************************************************************************/
357 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype)
359 /* invalid position in constantpool */
360 if (pos >= c->cpcount) {
361 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
365 /* constantpool entry of type 0 */
369 /* check type of constantpool entry */
370 if (c->cptags[pos] != ctype) {
371 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
375 return c->cpinfos[pos];
379 /* class_free ******************************************************************
381 Frees all resources used by the class.
383 *******************************************************************************/
385 void class_free(classinfo *c)
393 MFREE(c->interfaces, classinfo*, c->interfacescount);
396 for (i = 0; i < c->fieldscount; i++)
397 field_free(&(c->fields[i]));
398 /* MFREE(c->fields, fieldinfo, c->fieldscount); */
402 for (i = 0; i < c->methodscount; i++)
403 method_free(&(c->methods[i]));
404 MFREE(c->methods, methodinfo, c->methodscount);
407 if ((v = c->vftbl) != NULL) {
409 mem_free(v->arraydesc,sizeof(arraydescriptor));
411 for (i = 0; i < v->interfacetablelength; i++) {
412 MFREE(v->interfacetable[-i], methodptr, v->interfacevftbllength[i]);
414 MFREE(v->interfacevftbllength, s4, v->interfacetablelength);
416 i = sizeof(vftbl_t) + sizeof(methodptr) * (v->vftbllength - 1) +
417 sizeof(methodptr*) * (v->interfacetablelength -
418 (v->interfacetablelength > 0));
419 v = (vftbl_t*) (((methodptr*) v) -
420 (v->interfacetablelength - 1) * (v->interfacetablelength > 1));
425 MFREE(c->innerclass, innerclassinfo, c->innerclasscount);
427 /* if (c->classvftbl)
428 mem_free(c->header.vftbl, sizeof(vftbl) + sizeof(methodptr)*(c->vftbl->vftbllength-1)); */
434 /* get_array_class *************************************************************
436 Returns the array class with the given name for the given
437 classloader, or NULL if an exception occurred.
439 Note: This function does eager loading.
441 *******************************************************************************/
443 static classinfo *get_array_class(utf *name,java_objectheader *initloader,
444 java_objectheader *defloader,bool link)
448 /* lookup this class in the classcache */
449 c = classcache_lookup(initloader,name);
451 c = classcache_lookup_defined(defloader,name);
454 /* we have to create it */
455 c = class_create_classinfo(name);
456 c = load_newly_created_array(c,initloader);
462 CLASS_ASSERT(c->loaded);
463 CLASS_ASSERT(c->classloader == defloader);
465 if (link && !c->linked)
469 CLASS_ASSERT(!link || c->linked);
475 /* class_array_of **************************************************************
477 Returns an array class with the given component class. The array
478 class is dynamically created if neccessary.
480 *******************************************************************************/
482 classinfo *class_array_of(classinfo *component, bool link)
487 /* Assemble the array class name */
488 namelen = component->name->blength;
490 if (component->name->text[0] == '[') {
491 /* the component is itself an array */
492 namebuf = DMNEW(char, namelen + 1);
494 MCOPY(namebuf + 1, component->name->text, char, namelen);
498 /* the component is a non-array class */
499 namebuf = DMNEW(char, namelen + 3);
502 MCOPY(namebuf + 2, component->name->text, char, namelen);
503 namebuf[2 + namelen] = ';';
507 return get_array_class(utf_new(namebuf, namelen),
508 component->classloader,
509 component->classloader,
514 /* class_multiarray_of *********************************************************
516 Returns an array class with the given dimension and element class.
517 The array class is dynamically created if neccessary.
519 *******************************************************************************/
521 classinfo *class_multiarray_of(s4 dim, classinfo *element, bool link)
527 log_text("Invalid array dimension requested");
531 /* Assemble the array class name */
532 namelen = element->name->blength;
534 if (element->name->text[0] == '[') {
535 /* the element is itself an array */
536 namebuf = DMNEW(char, namelen + dim);
537 memcpy(namebuf + dim, element->name->text, namelen);
541 /* the element is a non-array class */
542 namebuf = DMNEW(char, namelen + 2 + dim);
544 memcpy(namebuf + dim + 1, element->name->text, namelen);
545 namelen += (2 + dim);
546 namebuf[namelen - 1] = ';';
548 memset(namebuf, '[', dim);
550 return get_array_class(utf_new(namebuf, namelen),
551 element->classloader,
552 element->classloader,
557 /* class_lookup_classref *******************************************************
559 Looks up the constant_classref for a given classname in the classref
563 cls..............the class containing the reference
564 name.............the name of the class refered to
567 a pointer to a constant_classref, or
568 NULL if the reference was not found
570 *******************************************************************************/
572 constant_classref *class_lookup_classref(classinfo *cls, utf *name)
574 constant_classref *ref;
575 extra_classref *xref;
580 CLASS_ASSERT(!cls->classrefcount || cls->classrefs);
582 /* first search the main classref table */
583 count = cls->classrefcount;
584 ref = cls->classrefs;
585 for (; count; --count, ++ref)
586 if (ref->name == name)
589 /* next try the list of extra classrefs */
590 for (xref = cls->extclassrefs; xref; xref = xref->next) {
591 if (xref->classref.name == name)
592 return &(xref->classref);
600 /* class_get_classref **********************************************************
602 Returns the constant_classref for a given classname.
605 cls..............the class containing the reference
606 name.............the name of the class refered to
609 a pointer to a constant_classref (never NULL)
612 The given name is not checked for validity!
614 *******************************************************************************/
616 constant_classref *class_get_classref(classinfo *cls, utf *name)
618 constant_classref *ref;
619 extra_classref *xref;
624 ref = class_lookup_classref(cls,name);
628 xref = NEW(extra_classref);
629 CLASSREF_INIT(xref->classref,cls,name);
631 xref->next = cls->extclassrefs;
632 cls->extclassrefs = xref;
634 return &(xref->classref);
638 /* class_get_self_classref *****************************************************
640 Returns the constant_classref to the class itself.
643 cls..............the class containing the reference
646 a pointer to a constant_classref (never NULL)
648 *******************************************************************************/
650 constant_classref *class_get_self_classref(classinfo *cls)
652 /* XXX this should be done in a faster way. Maybe always make */
653 /* the classref of index 0 a self reference. */
654 return class_get_classref(cls,cls->name);
657 /* class_get_classref_multiarray_of ********************************************
659 Returns an array type reference with the given dimension and element class
663 dim..............the requested dimension
664 dim must be in [1;255]. This is NOT checked!
665 ref..............the component class reference
668 a pointer to the class reference for the array type
671 The referer of `ref` is used as the referer for the new classref.
673 *******************************************************************************/
675 constant_classref *class_get_classref_multiarray_of(s4 dim, constant_classref *ref)
681 CLASS_ASSERT(dim >= 1 && dim <= 255);
683 /* Assemble the array class name */
684 namelen = ref->name->blength;
686 if (ref->name->text[0] == '[') {
687 /* the element is itself an array */
688 namebuf = DMNEW(char, namelen + dim);
689 memcpy(namebuf + dim, ref->name->text, namelen);
693 /* the element is a non-array class */
694 namebuf = DMNEW(char, namelen + 2 + dim);
696 memcpy(namebuf + dim + 1, ref->name->text, namelen);
697 namelen += (2 + dim);
698 namebuf[namelen - 1] = ';';
700 memset(namebuf, '[', dim);
702 return class_get_classref(ref->referer,utf_new(namebuf, namelen));
706 /* class_get_classref_component_of *********************************************
708 Returns the component classref of a given array type reference
711 ref..............the array type reference
714 a reference to the component class, or
715 NULL if `ref` is not an object array type reference
718 The referer of `ref` is used as the referer for the new classref.
720 *******************************************************************************/
722 constant_classref *class_get_classref_component_of(constant_classref *ref)
729 name = ref->name->text;
733 namelen = ref->name->blength - 1;
738 else if (*name != '[') {
742 return class_get_classref(ref->referer, utf_new(name, namelen));
746 /* class_findmethod ************************************************************
748 Searches a 'classinfo' structure for a method having the given name
749 and descriptor. If descriptor is NULL, it is ignored.
751 *******************************************************************************/
753 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc)
758 for (i = 0; i < c->methodscount; i++) {
759 m = &(c->methods[i]);
761 if ((m->name == name) && ((desc == NULL) || (m->descriptor == desc)))
769 /************************* Function: class_findmethod_approx ******************
771 like class_findmethod but ignores the return value when comparing the
774 *******************************************************************************/
776 methodinfo *class_findmethod_approx(classinfo *c, utf *name, utf *desc)
780 for (i = 0; i < c->methodscount; i++) {
781 if (c->methods[i].name == name) {
782 utf *meth_descr = c->methods[i].descriptor;
786 return &(c->methods[i]);
788 if (desc->blength <= meth_descr->blength) {
789 /* current position in utf text */
790 char *desc_utf_ptr = desc->text;
791 char *meth_utf_ptr = meth_descr->text;
792 /* points behind utf strings */
793 char *desc_end = UTF_END(desc);
794 char *meth_end = UTF_END(meth_descr);
797 /* compare argument types */
798 while (desc_utf_ptr < desc_end && meth_utf_ptr < meth_end) {
800 if ((ch = *desc_utf_ptr++) != (*meth_utf_ptr++))
801 break; /* no match */
804 return &(c->methods[i]); /* all parameter types equal */
814 /* class_resolvemethod *********************************************************
816 Searches a class and it's super classes for a method.
818 Superinterfaces are *not* searched.
820 *******************************************************************************/
822 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *desc)
827 m = class_findmethod(c, name, desc);
832 /* JVM Specification bug:
834 It is important NOT to resolve special <init> and <clinit>
835 methods to super classes or interfaces; yet, this is not
836 explicited in the specification. Section 5.4.3.3 should be
837 updated appropriately. */
839 if (name == utf_init || name == utf_clinit)
849 /* class_resolveinterfacemethod_intern *****************************************
851 Internally used helper function. Do not use this directly.
853 *******************************************************************************/
855 static methodinfo *class_resolveinterfacemethod_intern(classinfo *c,
856 utf *name, utf *desc)
861 m = class_findmethod(c, name, desc);
866 /* try the superinterfaces */
868 for (i = 0; i < c->interfacescount; i++) {
869 m = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
880 /* class_resolveclassmethod ****************************************************
882 Resolves a reference from REFERER to a method with NAME and DESC in
885 If the method cannot be resolved the return value is NULL. If
886 EXCEPT is true *exceptionptr is set, too.
888 *******************************************************************************/
890 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *desc,
891 classinfo *referer, bool except)
897 /* XXX resolve class c */
898 /* XXX check access from REFERER to C */
900 /* if (c->flags & ACC_INTERFACE) { */
902 /* *exceptionptr = */
903 /* new_exception(string_java_lang_IncompatibleClassChangeError); */
907 /* try class c and its superclasses */
911 m = class_resolvemethod(cls, name, desc);
916 /* try the superinterfaces */
918 for (i = 0; i < c->interfacescount; i++) {
919 m = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
927 *exceptionptr = exceptions_new_nosuchmethoderror(c, name, desc);
932 if ((m->flags & ACC_ABSTRACT) && !(c->flags & ACC_ABSTRACT)) {
934 *exceptionptr = new_exception(string_java_lang_AbstractMethodError);
939 /* XXX check access rights */
945 /* class_resolveinterfacemethod ************************************************
947 Resolves a reference from REFERER to a method with NAME and DESC in
950 If the method cannot be resolved the return value is NULL. If
951 EXCEPT is true *exceptionptr is set, too.
953 *******************************************************************************/
955 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *desc,
956 classinfo *referer, bool except)
960 /* XXX resolve class c */
961 /* XXX check access from REFERER to C */
963 if (!(c->flags & ACC_INTERFACE)) {
966 new_exception(string_java_lang_IncompatibleClassChangeError);
971 mi = class_resolveinterfacemethod_intern(c, name, desc);
976 /* try class java.lang.Object */
978 mi = class_findmethod(class_java_lang_Object, name, desc);
985 exceptions_new_nosuchmethoderror(c, name, desc);
991 /* class_findfield *************************************************************
993 Searches for field with specified name and type in a classinfo
994 structure. If no such field is found NULL is returned.
996 *******************************************************************************/
998 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc)
1002 for (i = 0; i < c->fieldscount; i++)
1003 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc))
1004 return &(c->fields[i]);
1007 return class_findfield(c->super.cls, name, desc);
1013 /* class_findfield_approx ******************************************************
1015 Searches in 'classinfo'-structure for a field with the specified
1018 *******************************************************************************/
1020 fieldinfo *class_findfield_by_name(classinfo *c, utf *name)
1024 /* get field index */
1026 i = class_findfield_index_by_name(c, name);
1028 /* field was not found, return */
1033 /* return field address */
1035 return &(c->fields[i]);
1039 s4 class_findfield_index_by_name(classinfo *c, utf *name)
1043 for (i = 0; i < c->fieldscount; i++) {
1044 /* compare field names */
1046 if ((c->fields[i].name == name))
1050 /* field was not found, raise exception */
1052 *exceptionptr = new_exception(string_java_lang_NoSuchFieldException);
1058 /****************** Function: class_resolvefield_int ***************************
1060 This is an internally used helper function. Do not use this directly.
1062 Tries to resolve a field having the given name and type.
1063 If the field cannot be resolved, NULL is returned.
1065 *******************************************************************************/
1067 static fieldinfo *class_resolvefield_int(classinfo *c, utf *name, utf *desc)
1072 /* search for field in class c */
1074 for (i = 0; i < c->fieldscount; i++) {
1075 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc)) {
1076 return &(c->fields[i]);
1080 /* try superinterfaces recursively */
1082 for (i = 0; i < c->interfacescount; i++) {
1083 fi = class_resolvefield_int(c->interfaces[i].cls, name, desc);
1088 /* try superclass */
1091 return class_resolvefield_int(c->super.cls, name, desc);
1099 /********************* Function: class_resolvefield ***************************
1101 Resolves a reference from REFERER to a field with NAME and DESC in class C.
1103 If the field cannot be resolved the return value is NULL. If EXCEPT is
1104 true *exceptionptr is set, too.
1106 *******************************************************************************/
1108 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc,
1109 classinfo *referer, bool except)
1113 /* XXX resolve class c */
1114 /* XXX check access from REFERER to C */
1116 fi = class_resolvefield_int(c, name, desc);
1121 new_exception_utfmessage(string_java_lang_NoSuchFieldError,
1127 /* XXX check access rights */
1133 /* class_issubclass ************************************************************
1135 Checks if sub is a descendant of super.
1137 *******************************************************************************/
1139 bool class_issubclass(classinfo *sub, classinfo *super)
1148 sub = sub->super.cls;
1153 #if defined(ENABLE_DEBUG)
1154 void class_showconstanti(classinfo *c, int ii)
1160 printf ("#%d: ", (int) i);
1162 switch (c->cptags [i]) {
1163 case CONSTANT_Class:
1164 printf("Classreference -> ");
1165 utf_display(((constant_classref*)e)->name);
1168 case CONSTANT_Fieldref:
1169 printf("Fieldref -> "); goto displayFMIi;
1170 case CONSTANT_Methodref:
1171 printf("Methodref -> "); goto displayFMIi;
1172 case CONSTANT_InterfaceMethodref:
1173 printf("InterfaceMethod -> "); goto displayFMIi;
1176 constant_FMIref *fmi = e;
1177 utf_display(fmi->classref->name);
1179 utf_display(fmi->name);
1181 utf_display(fmi->descriptor);
1185 case CONSTANT_String:
1186 printf("String -> ");
1189 case CONSTANT_Integer:
1190 printf("Integer -> %d", (int) (((constant_integer*)e)->value));
1192 case CONSTANT_Float:
1193 printf("Float -> %f", ((constant_float*)e)->value);
1195 case CONSTANT_Double:
1196 printf("Double -> %f", ((constant_double*)e)->value);
1200 u8 v = ((constant_long*)e)->value;
1202 printf("Long -> %ld", (long int) v);
1204 printf("Long -> HI: %ld, LO: %ld\n",
1205 (long int) v.high, (long int) v.low);
1209 case CONSTANT_NameAndType:
1211 constant_nameandtype *cnt = e;
1212 printf("NameAndType: ");
1213 utf_display(cnt->name);
1215 utf_display(cnt->descriptor);
1223 log_text("Invalid type of ConstantPool-Entry");
1231 void class_showconstantpool (classinfo *c)
1236 printf ("---- dump of constant pool ----\n");
1238 for (i=0; i<c->cpcount; i++) {
1239 printf ("#%d: ", (int) i);
1241 e = c -> cpinfos [i];
1244 switch (c -> cptags [i]) {
1245 case CONSTANT_Class:
1246 printf ("Classreference -> ");
1247 utf_display ( ((constant_classref*)e) -> name );
1250 case CONSTANT_Fieldref:
1251 printf ("Fieldref -> "); goto displayFMI;
1252 case CONSTANT_Methodref:
1253 printf ("Methodref -> "); goto displayFMI;
1254 case CONSTANT_InterfaceMethodref:
1255 printf ("InterfaceMethod -> "); goto displayFMI;
1258 constant_FMIref *fmi = e;
1259 utf_display ( fmi->classref->name );
1261 utf_display ( fmi->name);
1263 utf_display ( fmi->descriptor );
1267 case CONSTANT_String:
1268 printf ("String -> ");
1271 case CONSTANT_Integer:
1272 printf ("Integer -> %d", (int) ( ((constant_integer*)e) -> value) );
1274 case CONSTANT_Float:
1275 printf ("Float -> %f", ((constant_float*)e) -> value);
1277 case CONSTANT_Double:
1278 printf ("Double -> %f", ((constant_double*)e) -> value);
1282 u8 v = ((constant_long*)e) -> value;
1284 printf ("Long -> %ld", (long int) v);
1286 printf ("Long -> HI: %ld, LO: %ld\n",
1287 (long int) v.high, (long int) v.low);
1291 case CONSTANT_NameAndType:
1293 constant_nameandtype *cnt = e;
1294 printf ("NameAndType: ");
1295 utf_display (cnt->name);
1297 utf_display (cnt->descriptor);
1301 printf ("Utf8 -> ");
1305 log_text("Invalid type of ConstantPool-Entry");
1316 /********** Function: class_showmethods (debugging only) *************/
1318 void class_showmethods (classinfo *c)
1322 printf ("--------- Fields and Methods ----------------\n");
1323 printf ("Flags: "); printflags (c->flags); printf ("\n");
1325 printf ("This: "); utf_display (c->name); printf ("\n");
1327 printf ("Super: "); utf_display (c->super.cls->name); printf ("\n");
1329 printf ("Index: %d\n", c->index);
1331 printf ("interfaces:\n");
1332 for (i=0; i < c-> interfacescount; i++) {
1334 utf_display (c -> interfaces[i].cls -> name);
1335 printf (" (%d)\n", c->interfaces[i].cls -> index);
1338 printf ("fields:\n");
1339 for (i=0; i < c -> fieldscount; i++) {
1340 field_display (&(c -> fields[i]));
1343 printf ("methods:\n");
1344 for (i=0; i < c -> methodscount; i++) {
1345 methodinfo *m = &(c->methods[i]);
1346 if ( !(m->flags & ACC_STATIC))
1347 printf ("vftblindex: %d ", m->vftblindex);
1349 method_display ( m );
1353 printf ("Virtual function table:\n");
1354 for (i=0; i<c->vftbl->vftbllength; i++) {
1355 printf ("entry: %d, %ld\n", i, (long int) (c->vftbl->table[i]) );
1359 #endif /* defined(ENABLE_DEBUG) */
1363 * These are local overrides for various environment variables in Emacs.
1364 * Please do not remove this and leave it at the end of the file, where
1365 * Emacs will automagically detect them.
1366 * ---------------------------------------------------------------------
1369 * indent-tabs-mode: t