1 /* src/vm/class.c - class related functions
3 Copyright (C) 1996-2005, 2006 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 Contact: cacao@cacaojvm.org
27 Authors: Reinhard Grafl
34 $Id: class.c 5844 2006-10-28 12:49:29Z edwin $
47 #include "mm/memory.h"
49 #if defined(ENABLE_THREADS)
50 # include "threads/native/threads.h"
53 #include "toolbox/logging.h"
55 #include "vm/classcache.h"
56 #include "vm/exceptions.h"
57 #include "vm/global.h"
58 #include "vm/loader.h"
59 #include "vm/options.h"
60 #include "vm/resolve.h"
61 #include "vm/statistics.h"
62 #include "vm/stringlocal.h"
66 /* global variables ***********************************************************/
68 list unlinkedclasses; /* this is only used for eager class */
72 /* frequently used classes ****************************************************/
74 /* important system classes */
76 classinfo *class_java_lang_Object;
77 classinfo *class_java_lang_Class;
78 classinfo *class_java_lang_ClassLoader;
79 classinfo *class_java_lang_Cloneable;
80 classinfo *class_java_lang_SecurityManager;
81 classinfo *class_java_lang_String;
82 classinfo *class_java_lang_System;
83 classinfo *class_java_lang_Thread;
84 classinfo *class_java_lang_ThreadGroup;
85 classinfo *class_java_lang_VMSystem;
86 classinfo *class_java_lang_VMThread;
87 classinfo *class_java_io_Serializable;
90 /* system exception classes required in cacao */
92 classinfo *class_java_lang_Throwable;
93 classinfo *class_java_lang_VMThrowable;
94 classinfo *class_java_lang_Error;
95 classinfo *class_java_lang_AbstractMethodError;
96 classinfo *class_java_lang_LinkageError;
97 classinfo *class_java_lang_NoClassDefFoundError;
98 classinfo *class_java_lang_NoSuchMethodError;
99 classinfo *class_java_lang_OutOfMemoryError;
101 classinfo *class_java_lang_Exception;
102 classinfo *class_java_lang_ClassCastException;
103 classinfo *class_java_lang_ClassNotFoundException;
104 classinfo *class_java_lang_IllegalArgumentException;
105 classinfo *class_java_lang_IllegalMonitorStateException;
107 classinfo *class_java_lang_Void;
108 classinfo *class_java_lang_Boolean;
109 classinfo *class_java_lang_Byte;
110 classinfo *class_java_lang_Character;
111 classinfo *class_java_lang_Short;
112 classinfo *class_java_lang_Integer;
113 classinfo *class_java_lang_Long;
114 classinfo *class_java_lang_Float;
115 classinfo *class_java_lang_Double;
118 /* some runtime exception */
120 classinfo *class_java_lang_NullPointerException;
123 /* some classes which may be used more often */
125 classinfo *class_java_lang_StackTraceElement;
126 classinfo *class_java_lang_reflect_Constructor;
127 classinfo *class_java_lang_reflect_Field;
128 classinfo *class_java_lang_reflect_Method;
129 classinfo *class_java_security_PrivilegedAction;
130 classinfo *class_java_util_Vector;
132 classinfo *arrayclass_java_lang_Object;
135 /* pseudo classes for the typechecker */
137 classinfo *pseudo_class_Arraystub;
138 classinfo *pseudo_class_Null;
139 classinfo *pseudo_class_New;
142 /* class_set_packagename *******************************************************
144 Derive the package name from the class name and store it in the struct.
146 *******************************************************************************/
148 void class_set_packagename(classinfo *c)
150 char *p = UTF_END(c->name) - 1;
151 char *start = c->name->text;
153 /* set the package name */
154 /* classes in the unnamed package keep packagename == NULL */
156 if (c->name->text[0] == '[') {
157 /* set packagename of arrays to the element's package */
159 for (; *start == '['; start++);
161 /* skip the 'L' in arrays of references */
165 for (; (p > start) && (*p != '/'); --p);
167 c->packagename = utf_new(start, p - start);
170 for (; (p > start) && (*p != '/'); --p);
172 c->packagename = utf_new(start, p - start);
177 /* class_create_classinfo ******************************************************
179 Create a new classinfo struct. The class name is set to the given utf *,
180 most other fields are initialized to zero.
182 Note: classname may be NULL. In this case a not-yet-named classinfo is
183 created. The name must be filled in later and class_set_packagename
184 must be called after that.
186 *******************************************************************************/
188 classinfo *class_create_classinfo(utf *classname)
192 #if defined(ENABLE_STATISTICS)
194 size_classinfo += sizeof(classinfo);
197 /* we use a safe name for temporarily unnamed classes */
199 classname = utf_not_named_yet;
203 log_message_utf("Creating class: ", classname);
206 /* GCNEW_UNCOLLECTABLE clears the allocated memory */
208 c = GCNEW_UNCOLLECTABLE(classinfo, 1);
209 /*c=NEW(classinfo);*/
212 /* set the header.vftbl of all loaded classes to the one of
213 java.lang.Class, so Java code can use a class as object */
215 if (class_java_lang_Class)
216 if (class_java_lang_Class->vftbl)
217 c->object.header.vftbl = class_java_lang_Class->vftbl;
219 if (classname != utf_not_named_yet)
220 class_set_packagename(c);
222 #if defined(ENABLE_THREADS)
223 lock_init_object_lock(&c->object.header);
230 /* class_postset_header_vftbl **************************************************
232 Set the header.vftbl of all classes created before java.lang.Class
233 was linked. This is necessary that Java code can use a class as
236 *******************************************************************************/
238 void class_postset_header_vftbl(void)
242 classcache_name_entry *nmen;
243 classcache_class_entry *clsen;
245 assert(class_java_lang_Class);
247 for (slot = 0; slot < hashtable_classcache.size; slot++) {
248 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
250 for (; nmen; nmen = nmen->hashlink) {
251 /* iterate over all class entries */
253 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
256 /* now set the the vftbl */
258 if (c->object.header.vftbl == NULL)
259 c->object.header.vftbl = class_java_lang_Class->vftbl;
266 /* class_freepool **************************************************************
268 Frees all resources used by this classes Constant Pool.
270 *******************************************************************************/
272 static void class_freecpool(classinfo *c)
278 if (c->cptags && c->cpinfos) {
279 for (idx = 0; idx < c->cpcount; idx++) {
280 tag = c->cptags[idx];
281 info = c->cpinfos[idx];
285 case CONSTANT_Fieldref:
286 case CONSTANT_Methodref:
287 case CONSTANT_InterfaceMethodref:
288 FREE(info, constant_FMIref);
290 case CONSTANT_Integer:
291 FREE(info, constant_integer);
294 FREE(info, constant_float);
297 FREE(info, constant_long);
299 case CONSTANT_Double:
300 FREE(info, constant_double);
302 case CONSTANT_NameAndType:
303 FREE(info, constant_nameandtype);
311 MFREE(c->cptags, u1, c->cpcount);
314 MFREE(c->cpinfos, voidptr, c->cpcount);
318 /* class_getconstant ***********************************************************
320 Retrieves the value at position 'pos' of the constantpool of a
321 class. If the type of the value is other than 'ctype', an error is
324 *******************************************************************************/
326 voidptr class_getconstant(classinfo *c, u4 pos, u4 ctype)
328 /* check index and type of constantpool entry */
329 /* (pos == 0 is caught by type comparison) */
331 if (pos >= c->cpcount || c->cptags[pos] != ctype) {
332 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
336 return c->cpinfos[pos];
340 /* innerclass_getconstant ******************************************************
342 Like class_getconstant, but if cptags is ZERO, null is returned.
344 *******************************************************************************/
346 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype)
348 /* invalid position in constantpool */
349 if (pos >= c->cpcount) {
350 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
354 /* constantpool entry of type 0 */
358 /* check type of constantpool entry */
359 if (c->cptags[pos] != ctype) {
360 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
364 return c->cpinfos[pos];
368 /* class_free ******************************************************************
370 Frees all resources used by the class.
372 *******************************************************************************/
374 void class_free(classinfo *c)
382 MFREE(c->interfaces, classinfo*, c->interfacescount);
385 for (i = 0; i < c->fieldscount; i++)
386 field_free(&(c->fields[i]));
387 /* MFREE(c->fields, fieldinfo, c->fieldscount); */
391 for (i = 0; i < c->methodscount; i++)
392 method_free(&(c->methods[i]));
393 MFREE(c->methods, methodinfo, c->methodscount);
396 if ((v = c->vftbl) != NULL) {
398 mem_free(v->arraydesc,sizeof(arraydescriptor));
400 for (i = 0; i < v->interfacetablelength; i++) {
401 MFREE(v->interfacetable[-i], methodptr, v->interfacevftbllength[i]);
403 MFREE(v->interfacevftbllength, s4, v->interfacetablelength);
405 i = sizeof(vftbl_t) + sizeof(methodptr) * (v->vftbllength - 1) +
406 sizeof(methodptr*) * (v->interfacetablelength -
407 (v->interfacetablelength > 0));
408 v = (vftbl_t*) (((methodptr*) v) -
409 (v->interfacetablelength - 1) * (v->interfacetablelength > 1));
414 MFREE(c->innerclass, innerclassinfo, c->innerclasscount);
416 /* if (c->classvftbl)
417 mem_free(c->header.vftbl, sizeof(vftbl) + sizeof(methodptr)*(c->vftbl->vftbllength-1)); */
423 /* get_array_class *************************************************************
425 Returns the array class with the given name for the given
426 classloader, or NULL if an exception occurred.
428 Note: This function does eager loading.
430 *******************************************************************************/
432 static classinfo *get_array_class(utf *name,java_objectheader *initloader,
433 java_objectheader *defloader,bool link)
437 /* lookup this class in the classcache */
438 c = classcache_lookup(initloader,name);
440 c = classcache_lookup_defined(defloader,name);
443 /* we have to create it */
444 c = class_create_classinfo(name);
445 c = load_newly_created_array(c,initloader);
451 assert(c->state & CLASS_LOADED);
452 assert(c->classloader == defloader);
454 if (link && !(c->state & CLASS_LINKED))
458 assert(!link || (c->state & CLASS_LINKED));
464 /* class_array_of **************************************************************
466 Returns an array class with the given component class. The array
467 class is dynamically created if neccessary.
469 *******************************************************************************/
471 classinfo *class_array_of(classinfo *component, bool link)
478 dumpsize = dump_size();
480 /* Assemble the array class name */
481 namelen = component->name->blength;
483 if (component->name->text[0] == '[') {
484 /* the component is itself an array */
485 namebuf = DMNEW(char, namelen + 1);
487 MCOPY(namebuf + 1, component->name->text, char, namelen);
491 /* the component is a non-array class */
492 namebuf = DMNEW(char, namelen + 3);
495 MCOPY(namebuf + 2, component->name->text, char, namelen);
496 namebuf[2 + namelen] = ';';
500 c = get_array_class(utf_new(namebuf, namelen),
501 component->classloader,
502 component->classloader,
505 dump_release(dumpsize);
511 /* class_multiarray_of *********************************************************
513 Returns an array class with the given dimension and element class.
514 The array class is dynamically created if neccessary.
516 *******************************************************************************/
518 classinfo *class_multiarray_of(s4 dim, classinfo *element, bool link)
525 dumpsize = dump_size();
528 log_text("Invalid array dimension requested");
532 /* Assemble the array class name */
533 namelen = element->name->blength;
535 if (element->name->text[0] == '[') {
536 /* the element is itself an array */
537 namebuf = DMNEW(char, namelen + dim);
538 memcpy(namebuf + dim, element->name->text, namelen);
542 /* the element is a non-array class */
543 namebuf = DMNEW(char, namelen + 2 + dim);
545 memcpy(namebuf + dim + 1, element->name->text, namelen);
546 namelen += (2 + dim);
547 namebuf[namelen - 1] = ';';
549 memset(namebuf, '[', dim);
551 c = get_array_class(utf_new(namebuf, namelen),
552 element->classloader,
553 element->classloader,
556 dump_release(dumpsize);
562 /* class_lookup_classref *******************************************************
564 Looks up the constant_classref for a given classname in the classref
568 cls..............the class containing the reference
569 name.............the name of the class refered to
572 a pointer to a constant_classref, or
573 NULL if the reference was not found
575 *******************************************************************************/
577 constant_classref *class_lookup_classref(classinfo *cls, utf *name)
579 constant_classref *ref;
580 extra_classref *xref;
585 assert(!cls->classrefcount || cls->classrefs);
587 /* first search the main classref table */
588 count = cls->classrefcount;
589 ref = cls->classrefs;
590 for (; count; --count, ++ref)
591 if (ref->name == name)
594 /* next try the list of extra classrefs */
595 for (xref = cls->extclassrefs; xref; xref = xref->next) {
596 if (xref->classref.name == name)
597 return &(xref->classref);
605 /* class_get_classref **********************************************************
607 Returns the constant_classref for a given classname.
610 cls..............the class containing the reference
611 name.............the name of the class refered to
614 a pointer to a constant_classref (never NULL)
617 The given name is not checked for validity!
619 *******************************************************************************/
621 constant_classref *class_get_classref(classinfo *cls, utf *name)
623 constant_classref *ref;
624 extra_classref *xref;
629 ref = class_lookup_classref(cls,name);
633 xref = NEW(extra_classref);
634 CLASSREF_INIT(xref->classref,cls,name);
636 xref->next = cls->extclassrefs;
637 cls->extclassrefs = xref;
639 return &(xref->classref);
643 /* class_get_self_classref *****************************************************
645 Returns the constant_classref to the class itself.
648 cls..............the class containing the reference
651 a pointer to a constant_classref (never NULL)
653 *******************************************************************************/
655 constant_classref *class_get_self_classref(classinfo *cls)
657 /* XXX this should be done in a faster way. Maybe always make */
658 /* the classref of index 0 a self reference. */
659 return class_get_classref(cls,cls->name);
662 /* class_get_classref_multiarray_of ********************************************
664 Returns an array type reference with the given dimension and element class
668 dim..............the requested dimension
669 dim must be in [1;255]. This is NOT checked!
670 ref..............the component class reference
673 a pointer to the class reference for the array type
676 The referer of `ref` is used as the referer for the new classref.
678 *******************************************************************************/
680 constant_classref *class_get_classref_multiarray_of(s4 dim, constant_classref *ref)
685 constant_classref *cr;
688 assert(dim >= 1 && dim <= 255);
690 dumpsize = dump_size();
692 /* Assemble the array class name */
693 namelen = ref->name->blength;
695 if (ref->name->text[0] == '[') {
696 /* the element is itself an array */
697 namebuf = DMNEW(char, namelen + dim);
698 memcpy(namebuf + dim, ref->name->text, namelen);
702 /* the element is a non-array class */
703 namebuf = DMNEW(char, namelen + 2 + dim);
705 memcpy(namebuf + dim + 1, ref->name->text, namelen);
706 namelen += (2 + dim);
707 namebuf[namelen - 1] = ';';
709 memset(namebuf, '[', dim);
711 cr = class_get_classref(ref->referer,utf_new(namebuf, namelen));
713 dump_release(dumpsize);
719 /* class_get_classref_component_of *********************************************
721 Returns the component classref of a given array type reference
724 ref..............the array type reference
727 a reference to the component class, or
728 NULL if `ref` is not an object array type reference
731 The referer of `ref` is used as the referer for the new classref.
733 *******************************************************************************/
735 constant_classref *class_get_classref_component_of(constant_classref *ref)
742 name = ref->name->text;
746 namelen = ref->name->blength - 1;
751 else if (*name != '[') {
755 return class_get_classref(ref->referer, utf_new(name, namelen));
759 /* class_findmethod ************************************************************
761 Searches a 'classinfo' structure for a method having the given name
762 and descriptor. If descriptor is NULL, it is ignored.
764 *******************************************************************************/
766 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc)
771 for (i = 0; i < c->methodscount; i++) {
772 m = &(c->methods[i]);
774 if ((m->name == name) && ((desc == NULL) || (m->descriptor == desc)))
782 /* class_resolvemethod *********************************************************
784 Searches a class and it's super classes for a method.
786 Superinterfaces are *not* searched.
788 *******************************************************************************/
790 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *desc)
795 m = class_findmethod(c, name, desc);
800 /* JVM Specification bug:
802 It is important NOT to resolve special <init> and <clinit>
803 methods to super classes or interfaces; yet, this is not
804 explicited in the specification. Section 5.4.3.3 should be
805 updated appropriately. */
807 if (name == utf_init || name == utf_clinit)
817 /* class_resolveinterfacemethod_intern *****************************************
819 Internally used helper function. Do not use this directly.
821 *******************************************************************************/
823 static methodinfo *class_resolveinterfacemethod_intern(classinfo *c,
824 utf *name, utf *desc)
829 /* try to find the method in the class */
831 m = class_findmethod(c, name, desc);
836 /* no method found? try the superinterfaces */
838 for (i = 0; i < c->interfacescount; i++) {
839 m = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
846 /* no method found */
852 /* class_resolveclassmethod ****************************************************
854 Resolves a reference from REFERER to a method with NAME and DESC in
857 If the method cannot be resolved the return value is NULL. If
858 EXCEPT is true *exceptionptr is set, too.
860 *******************************************************************************/
862 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *desc,
863 classinfo *referer, bool throwexception)
869 /* if (c->flags & ACC_INTERFACE) { */
870 /* if (throwexception) */
871 /* *exceptionptr = */
872 /* new_exception(string_java_lang_IncompatibleClassChangeError); */
876 /* try class c and its superclasses */
880 m = class_resolvemethod(cls, name, desc);
885 /* try the superinterfaces */
887 for (i = 0; i < c->interfacescount; i++) {
888 m = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
896 exceptions_throw_nosuchmethoderror(c, name, desc);
901 if ((m->flags & ACC_ABSTRACT) && !(c->flags & ACC_ABSTRACT)) {
903 exceptions_throw_abstractmethoderror();
908 /* XXX check access rights */
914 /* class_resolveinterfacemethod ************************************************
916 Resolves a reference from REFERER to a method with NAME and DESC in
919 If the method cannot be resolved the return value is NULL. If
920 EXCEPT is true *exceptionptr is set, too.
922 *******************************************************************************/
924 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *desc,
925 classinfo *referer, bool throwexception)
929 if (!(c->flags & ACC_INTERFACE)) {
932 new_exception(string_java_lang_IncompatibleClassChangeError);
937 mi = class_resolveinterfacemethod_intern(c, name, desc);
942 /* try class java.lang.Object */
944 mi = class_findmethod(class_java_lang_Object, name, desc);
951 exceptions_new_nosuchmethoderror(c, name, desc);
957 /* class_findfield *************************************************************
959 Searches for field with specified name and type in a classinfo
960 structure. If no such field is found NULL is returned.
962 *******************************************************************************/
964 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc)
968 for (i = 0; i < c->fieldscount; i++)
969 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc))
970 return &(c->fields[i]);
973 return class_findfield(c->super.cls, name, desc);
979 /* class_findfield_approx ******************************************************
981 Searches in 'classinfo'-structure for a field with the specified
984 *******************************************************************************/
986 fieldinfo *class_findfield_by_name(classinfo *c, utf *name)
990 /* get field index */
992 i = class_findfield_index_by_name(c, name);
994 /* field was not found, return */
999 /* return field address */
1001 return &(c->fields[i]);
1005 s4 class_findfield_index_by_name(classinfo *c, utf *name)
1009 for (i = 0; i < c->fieldscount; i++) {
1010 /* compare field names */
1012 if ((c->fields[i].name == name))
1016 /* field was not found, raise exception */
1018 *exceptionptr = new_exception(string_java_lang_NoSuchFieldException);
1024 /****************** Function: class_resolvefield_int ***************************
1026 This is an internally used helper function. Do not use this directly.
1028 Tries to resolve a field having the given name and type.
1029 If the field cannot be resolved, NULL is returned.
1031 *******************************************************************************/
1033 static fieldinfo *class_resolvefield_int(classinfo *c, utf *name, utf *desc)
1038 /* search for field in class c */
1040 for (i = 0; i < c->fieldscount; i++) {
1041 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc)) {
1042 return &(c->fields[i]);
1046 /* try superinterfaces recursively */
1048 for (i = 0; i < c->interfacescount; i++) {
1049 fi = class_resolvefield_int(c->interfaces[i].cls, name, desc);
1054 /* try superclass */
1057 return class_resolvefield_int(c->super.cls, name, desc);
1065 /********************* Function: class_resolvefield ***************************
1067 Resolves a reference from REFERER to a field with NAME and DESC in class C.
1069 If the field cannot be resolved the return value is NULL. If EXCEPT is
1070 true *exceptionptr is set, too.
1072 *******************************************************************************/
1074 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc,
1075 classinfo *referer, bool throwexception)
1079 fi = class_resolvefield_int(c, name, desc);
1084 new_exception_utfmessage(string_java_lang_NoSuchFieldError,
1090 /* XXX check access rights */
1096 /* class_issubclass ************************************************************
1098 Checks if sub is a descendant of super.
1100 *******************************************************************************/
1102 bool class_issubclass(classinfo *sub, classinfo *super)
1111 sub = sub->super.cls;
1116 /* class_printflags ************************************************************
1118 Prints flags of a class.
1120 *******************************************************************************/
1122 #if !defined(NDEBUG)
1123 void class_printflags(classinfo *c)
1130 if (c->flags & ACC_PUBLIC) printf(" PUBLIC");
1131 if (c->flags & ACC_PRIVATE) printf(" PRIVATE");
1132 if (c->flags & ACC_PROTECTED) printf(" PROTECTED");
1133 if (c->flags & ACC_STATIC) printf(" STATIC");
1134 if (c->flags & ACC_FINAL) printf(" FINAL");
1135 if (c->flags & ACC_SYNCHRONIZED) printf(" SYNCHRONIZED");
1136 if (c->flags & ACC_VOLATILE) printf(" VOLATILE");
1137 if (c->flags & ACC_TRANSIENT) printf(" TRANSIENT");
1138 if (c->flags & ACC_NATIVE) printf(" NATIVE");
1139 if (c->flags & ACC_INTERFACE) printf(" INTERFACE");
1140 if (c->flags & ACC_ABSTRACT) printf(" ABSTRACT");
1145 /* class_print *****************************************************************
1147 Prints classname plus flags.
1149 *******************************************************************************/
1151 #if !defined(NDEBUG)
1152 void class_print(classinfo *c)
1159 utf_display_printable_ascii(c->name);
1160 class_printflags(c);
1165 /* class_classref_print ********************************************************
1167 Prints classname plus referer class.
1169 *******************************************************************************/
1171 #if !defined(NDEBUG)
1172 void class_classref_print(constant_classref *cr)
1179 utf_display_printable_ascii(cr->name);
1182 class_print(cr->referer);
1190 /* class_println ***************************************************************
1192 Prints classname plus flags and new line.
1194 *******************************************************************************/
1196 #if !defined(NDEBUG)
1197 void class_println(classinfo *c)
1205 /* class_classref_println ******************************************************
1207 Prints classname plus referer class and new line.
1209 *******************************************************************************/
1211 #if !defined(NDEBUG)
1212 void class_classref_println(constant_classref *cr)
1214 class_classref_print(cr);
1220 /* class_classref_or_classinfo_print *******************************************
1222 Prints classname plus referer class.
1224 *******************************************************************************/
1226 #if !defined(NDEBUG)
1227 void class_classref_or_classinfo_print(classref_or_classinfo c)
1229 if (c.any == NULL) {
1230 printf("(classref_or_classinfo) NULL");
1234 class_classref_print(c.ref);
1241 /* class_classref_or_classinfo_println *****************************************
1243 Prints classname plus referer class and a newline.
1245 *******************************************************************************/
1247 void class_classref_or_classinfo_println(classref_or_classinfo c)
1249 class_classref_or_classinfo_println(c);
1254 /* class_showconstantpool ******************************************************
1256 Dump the constant pool of the given class to stdout.
1258 *******************************************************************************/
1260 #if !defined(NDEBUG)
1261 void class_showconstantpool (classinfo *c)
1266 printf ("---- dump of constant pool ----\n");
1268 for (i=0; i<c->cpcount; i++) {
1269 printf ("#%d: ", (int) i);
1271 e = c -> cpinfos [i];
1274 switch (c -> cptags [i]) {
1275 case CONSTANT_Class:
1276 printf ("Classreference -> ");
1277 utf_display_printable_ascii ( ((constant_classref*)e) -> name );
1279 case CONSTANT_Fieldref:
1280 printf ("Fieldref -> ");
1281 field_fieldref_print((constant_FMIref *) e);
1283 case CONSTANT_Methodref:
1284 printf ("Methodref -> ");
1285 method_methodref_print((constant_FMIref *) e);
1287 case CONSTANT_InterfaceMethodref:
1288 printf ("InterfaceMethod -> ");
1289 method_methodref_print((constant_FMIref *) e);
1291 case CONSTANT_String:
1292 printf ("String -> ");
1293 utf_display_printable_ascii (e);
1295 case CONSTANT_Integer:
1296 printf ("Integer -> %d", (int) ( ((constant_integer*)e) -> value) );
1298 case CONSTANT_Float:
1299 printf ("Float -> %f", ((constant_float*)e) -> value);
1301 case CONSTANT_Double:
1302 printf ("Double -> %f", ((constant_double*)e) -> value);
1306 u8 v = ((constant_long*)e) -> value;
1308 printf ("Long -> %ld", (long int) v);
1310 printf ("Long -> HI: %ld, LO: %ld\n",
1311 (long int) v.high, (long int) v.low);
1315 case CONSTANT_NameAndType:
1317 constant_nameandtype *cnt = e;
1318 printf ("NameAndType: ");
1319 utf_display_printable_ascii (cnt->name);
1321 utf_display_printable_ascii (cnt->descriptor);
1325 printf ("Utf8 -> ");
1326 utf_display_printable_ascii (e);
1329 log_text("Invalid type of ConstantPool-Entry");
1337 #endif /* !defined(NDEBUG) */
1340 /* class_showmethods ***********************************************************
1342 Dump info about the fields and methods of the given class to stdout.
1344 *******************************************************************************/
1346 #if !defined(NDEBUG)
1347 void class_showmethods (classinfo *c)
1351 printf("--------- Fields and Methods ----------------\n");
1353 class_printflags(c);
1357 utf_display_printable_ascii(c->name);
1362 utf_display_printable_ascii(c->super.cls->name);
1366 printf("Index: %d\n", c->index);
1368 printf("Interfaces:\n");
1369 for (i = 0; i < c->interfacescount; i++) {
1371 utf_display_printable_ascii(c->interfaces[i].cls->name);
1372 printf (" (%d)\n", c->interfaces[i].cls->index);
1375 printf("Fields:\n");
1376 for (i = 0; i < c->fieldscount; i++)
1377 field_println(&(c->fields[i]));
1379 printf("Methods:\n");
1380 for (i = 0; i < c->methodscount; i++) {
1381 methodinfo *m = &(c->methods[i]);
1383 if (!(m->flags & ACC_STATIC))
1384 printf("vftblindex: %d ", m->vftblindex);
1389 printf ("Virtual function table:\n");
1390 for (i = 0; i < c->vftbl->vftbllength; i++)
1391 printf ("entry: %d, %ld\n", i, (long int) (c->vftbl->table[i]));
1393 #endif /* !defined(NDEBUG) */
1397 * These are local overrides for various environment variables in Emacs.
1398 * Please do not remove this and leave it at the end of the file, where
1399 * Emacs will automagically detect them.
1400 * ---------------------------------------------------------------------
1403 * indent-tabs-mode: t
1407 * vim:noexpandtab:sw=4:ts=4: