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 5093 2006-07-10 13:36:47Z twisti $
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 /******************************************************************************/
68 /******************************************************************************/
75 #define CLASS_ASSERT(cond) assert(cond)
77 #define CLASS_ASSERT(cond)
81 /* global variables ***********************************************************/
83 list unlinkedclasses; /* this is only used for eager class */
87 /* frequently used classes ****************************************************/
89 /* important system classes */
91 classinfo *class_java_lang_Object;
92 classinfo *class_java_lang_Class;
93 classinfo *class_java_lang_ClassLoader;
94 classinfo *class_java_lang_Cloneable;
95 classinfo *class_java_lang_SecurityManager;
96 classinfo *class_java_lang_String;
97 classinfo *class_java_lang_System;
98 classinfo *class_java_lang_Thread;
99 classinfo *class_java_lang_ThreadGroup;
100 classinfo *class_java_lang_VMThread;
101 classinfo *class_java_io_Serializable;
104 /* system exception classes required in cacao */
106 classinfo *class_java_lang_Throwable;
107 classinfo *class_java_lang_VMThrowable;
108 classinfo *class_java_lang_Error;
109 classinfo *class_java_lang_AbstractMethodError;
110 classinfo *class_java_lang_LinkageError;
111 classinfo *class_java_lang_NoClassDefFoundError;
112 classinfo *class_java_lang_NoSuchMethodError;
113 classinfo *class_java_lang_OutOfMemoryError;
115 classinfo *class_java_lang_Exception;
116 classinfo *class_java_lang_ClassCastException;
117 classinfo *class_java_lang_ClassNotFoundException;
118 classinfo *class_java_lang_IllegalArgumentException;
119 classinfo *class_java_lang_IllegalMonitorStateException;
121 classinfo *class_java_lang_Void;
122 classinfo *class_java_lang_Boolean;
123 classinfo *class_java_lang_Byte;
124 classinfo *class_java_lang_Character;
125 classinfo *class_java_lang_Short;
126 classinfo *class_java_lang_Integer;
127 classinfo *class_java_lang_Long;
128 classinfo *class_java_lang_Float;
129 classinfo *class_java_lang_Double;
132 /* some runtime exception */
134 classinfo *class_java_lang_NullPointerException;
137 /* some classes which may be used more often */
139 classinfo *class_java_lang_StackTraceElement;
140 classinfo *class_java_lang_reflect_Constructor;
141 classinfo *class_java_lang_reflect_Field;
142 classinfo *class_java_lang_reflect_Method;
143 classinfo *class_java_security_PrivilegedAction;
144 classinfo *class_java_util_Vector;
146 classinfo *arrayclass_java_lang_Object;
149 /* pseudo classes for the typechecker */
151 classinfo *pseudo_class_Arraystub;
152 classinfo *pseudo_class_Null;
153 classinfo *pseudo_class_New;
156 /* class_set_packagename *******************************************************
158 Derive the package name from the class name and store it in the struct.
160 *******************************************************************************/
162 void class_set_packagename(classinfo *c)
164 char *p = UTF_END(c->name) - 1;
165 char *start = c->name->text;
167 /* set the package name */
168 /* classes in the unnamed package keep packagename == NULL */
170 if (c->name->text[0] == '[') {
171 /* set packagename of arrays to the element's package */
173 for (; *start == '['; start++);
175 /* skip the 'L' in arrays of references */
179 for (; (p > start) && (*p != '/'); --p);
181 c->packagename = utf_new(start, p - start);
184 for (; (p > start) && (*p != '/'); --p);
186 c->packagename = utf_new(start, p - start);
191 /* class_create_classinfo ******************************************************
193 Create a new classinfo struct. The class name is set to the given utf *,
194 most other fields are initialized to zero.
196 Note: classname may be NULL. In this case a not-yet-named classinfo is
197 created. The name must be filled in later and class_set_packagename
198 must be called after that.
200 *******************************************************************************/
202 classinfo *class_create_classinfo(utf *classname)
206 #if defined(ENABLE_STATISTICS)
208 size_classinfo += sizeof(classinfo);
211 /* we use a safe name for temporarily unnamed classes */
213 classname = utf_not_named_yet;
217 log_message_utf("Creating class: ", classname);
220 /* GCNEW_UNCOLLECTABLE clears the allocated memory */
222 c = GCNEW_UNCOLLECTABLE(classinfo, 1);
223 /*c=NEW(classinfo);*/
226 /* set the header.vftbl of all loaded classes to the one of
227 java.lang.Class, so Java code can use a class as object */
229 if (class_java_lang_Class)
230 if (class_java_lang_Class->vftbl)
231 c->object.header.vftbl = class_java_lang_Class->vftbl;
233 if (classname != utf_not_named_yet)
234 class_set_packagename(c);
236 #if defined(ENABLE_THREADS)
237 lock_init_object_lock(&c->object.header);
244 /* class_postset_header_vftbl **************************************************
246 Set the header.vftbl of all classes created before java.lang.Class
247 was linked. This is necessary that Java code can use a class as
250 *******************************************************************************/
252 void class_postset_header_vftbl(void)
256 classcache_name_entry *nmen;
257 classcache_class_entry *clsen;
259 assert(class_java_lang_Class);
261 for (slot = 0; slot < hashtable_classcache.size; slot++) {
262 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
264 for (; nmen; nmen = nmen->hashlink) {
265 /* iterate over all class entries */
267 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
270 /* now set the the vftbl */
272 if (c->object.header.vftbl == NULL)
273 c->object.header.vftbl = class_java_lang_Class->vftbl;
280 /* class_freepool **************************************************************
282 Frees all resources used by this classes Constant Pool.
284 *******************************************************************************/
286 static void class_freecpool(classinfo *c)
292 if (c->cptags && c->cpinfos) {
293 for (idx = 0; idx < c->cpcount; idx++) {
294 tag = c->cptags[idx];
295 info = c->cpinfos[idx];
299 case CONSTANT_Fieldref:
300 case CONSTANT_Methodref:
301 case CONSTANT_InterfaceMethodref:
302 FREE(info, constant_FMIref);
304 case CONSTANT_Integer:
305 FREE(info, constant_integer);
308 FREE(info, constant_float);
311 FREE(info, constant_long);
313 case CONSTANT_Double:
314 FREE(info, constant_double);
316 case CONSTANT_NameAndType:
317 FREE(info, constant_nameandtype);
325 MFREE(c->cptags, u1, c->cpcount);
328 MFREE(c->cpinfos, voidptr, c->cpcount);
332 /* class_getconstant ***********************************************************
334 Retrieves the value at position 'pos' of the constantpool of a
335 class. If the type of the value is other than 'ctype', an error is
338 *******************************************************************************/
340 voidptr class_getconstant(classinfo *c, u4 pos, u4 ctype)
342 /* check index and type of constantpool entry */
343 /* (pos == 0 is caught by type comparison) */
345 if (pos >= c->cpcount || c->cptags[pos] != ctype) {
346 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
350 return c->cpinfos[pos];
354 /* innerclass_getconstant ******************************************************
356 Like class_getconstant, but if cptags is ZERO, null is returned.
358 *******************************************************************************/
360 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype)
362 /* invalid position in constantpool */
363 if (pos >= c->cpcount) {
364 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
368 /* constantpool entry of type 0 */
372 /* check type of constantpool entry */
373 if (c->cptags[pos] != ctype) {
374 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
378 return c->cpinfos[pos];
382 /* class_free ******************************************************************
384 Frees all resources used by the class.
386 *******************************************************************************/
388 void class_free(classinfo *c)
396 MFREE(c->interfaces, classinfo*, c->interfacescount);
399 for (i = 0; i < c->fieldscount; i++)
400 field_free(&(c->fields[i]));
401 /* MFREE(c->fields, fieldinfo, c->fieldscount); */
405 for (i = 0; i < c->methodscount; i++)
406 method_free(&(c->methods[i]));
407 MFREE(c->methods, methodinfo, c->methodscount);
410 if ((v = c->vftbl) != NULL) {
412 mem_free(v->arraydesc,sizeof(arraydescriptor));
414 for (i = 0; i < v->interfacetablelength; i++) {
415 MFREE(v->interfacetable[-i], methodptr, v->interfacevftbllength[i]);
417 MFREE(v->interfacevftbllength, s4, v->interfacetablelength);
419 i = sizeof(vftbl_t) + sizeof(methodptr) * (v->vftbllength - 1) +
420 sizeof(methodptr*) * (v->interfacetablelength -
421 (v->interfacetablelength > 0));
422 v = (vftbl_t*) (((methodptr*) v) -
423 (v->interfacetablelength - 1) * (v->interfacetablelength > 1));
428 MFREE(c->innerclass, innerclassinfo, c->innerclasscount);
430 /* if (c->classvftbl)
431 mem_free(c->header.vftbl, sizeof(vftbl) + sizeof(methodptr)*(c->vftbl->vftbllength-1)); */
437 /* get_array_class *************************************************************
439 Returns the array class with the given name for the given
440 classloader, or NULL if an exception occurred.
442 Note: This function does eager loading.
444 *******************************************************************************/
446 static classinfo *get_array_class(utf *name,java_objectheader *initloader,
447 java_objectheader *defloader,bool link)
451 /* lookup this class in the classcache */
452 c = classcache_lookup(initloader,name);
454 c = classcache_lookup_defined(defloader,name);
457 /* we have to create it */
458 c = class_create_classinfo(name);
459 c = load_newly_created_array(c,initloader);
465 CLASS_ASSERT(c->state & CLASS_LOADED);
466 CLASS_ASSERT(c->classloader == defloader);
468 if (link && !(c->state & CLASS_LINKED))
472 CLASS_ASSERT(!link || (c->state & CLASS_LINKED));
478 /* class_array_of **************************************************************
480 Returns an array class with the given component class. The array
481 class is dynamically created if neccessary.
483 *******************************************************************************/
485 classinfo *class_array_of(classinfo *component, bool link)
490 /* Assemble the array class name */
491 namelen = component->name->blength;
493 if (component->name->text[0] == '[') {
494 /* the component is itself an array */
495 namebuf = DMNEW(char, namelen + 1);
497 MCOPY(namebuf + 1, component->name->text, char, namelen);
501 /* the component is a non-array class */
502 namebuf = DMNEW(char, namelen + 3);
505 MCOPY(namebuf + 2, component->name->text, char, namelen);
506 namebuf[2 + namelen] = ';';
510 return get_array_class(utf_new(namebuf, namelen),
511 component->classloader,
512 component->classloader,
517 /* class_multiarray_of *********************************************************
519 Returns an array class with the given dimension and element class.
520 The array class is dynamically created if neccessary.
522 *******************************************************************************/
524 classinfo *class_multiarray_of(s4 dim, classinfo *element, bool link)
530 log_text("Invalid array dimension requested");
534 /* Assemble the array class name */
535 namelen = element->name->blength;
537 if (element->name->text[0] == '[') {
538 /* the element is itself an array */
539 namebuf = DMNEW(char, namelen + dim);
540 memcpy(namebuf + dim, element->name->text, namelen);
544 /* the element is a non-array class */
545 namebuf = DMNEW(char, namelen + 2 + dim);
547 memcpy(namebuf + dim + 1, element->name->text, namelen);
548 namelen += (2 + dim);
549 namebuf[namelen - 1] = ';';
551 memset(namebuf, '[', dim);
553 return get_array_class(utf_new(namebuf, namelen),
554 element->classloader,
555 element->classloader,
560 /* class_lookup_classref *******************************************************
562 Looks up the constant_classref for a given classname in the classref
566 cls..............the class containing the reference
567 name.............the name of the class refered to
570 a pointer to a constant_classref, or
571 NULL if the reference was not found
573 *******************************************************************************/
575 constant_classref *class_lookup_classref(classinfo *cls, utf *name)
577 constant_classref *ref;
578 extra_classref *xref;
583 CLASS_ASSERT(!cls->classrefcount || cls->classrefs);
585 /* first search the main classref table */
586 count = cls->classrefcount;
587 ref = cls->classrefs;
588 for (; count; --count, ++ref)
589 if (ref->name == name)
592 /* next try the list of extra classrefs */
593 for (xref = cls->extclassrefs; xref; xref = xref->next) {
594 if (xref->classref.name == name)
595 return &(xref->classref);
603 /* class_get_classref **********************************************************
605 Returns the constant_classref for a given classname.
608 cls..............the class containing the reference
609 name.............the name of the class refered to
612 a pointer to a constant_classref (never NULL)
615 The given name is not checked for validity!
617 *******************************************************************************/
619 constant_classref *class_get_classref(classinfo *cls, utf *name)
621 constant_classref *ref;
622 extra_classref *xref;
627 ref = class_lookup_classref(cls,name);
631 xref = NEW(extra_classref);
632 CLASSREF_INIT(xref->classref,cls,name);
634 xref->next = cls->extclassrefs;
635 cls->extclassrefs = xref;
637 return &(xref->classref);
641 /* class_get_self_classref *****************************************************
643 Returns the constant_classref to the class itself.
646 cls..............the class containing the reference
649 a pointer to a constant_classref (never NULL)
651 *******************************************************************************/
653 constant_classref *class_get_self_classref(classinfo *cls)
655 /* XXX this should be done in a faster way. Maybe always make */
656 /* the classref of index 0 a self reference. */
657 return class_get_classref(cls,cls->name);
660 /* class_get_classref_multiarray_of ********************************************
662 Returns an array type reference with the given dimension and element class
666 dim..............the requested dimension
667 dim must be in [1;255]. This is NOT checked!
668 ref..............the component class reference
671 a pointer to the class reference for the array type
674 The referer of `ref` is used as the referer for the new classref.
676 *******************************************************************************/
678 constant_classref *class_get_classref_multiarray_of(s4 dim, constant_classref *ref)
684 CLASS_ASSERT(dim >= 1 && dim <= 255);
686 /* Assemble the array class name */
687 namelen = ref->name->blength;
689 if (ref->name->text[0] == '[') {
690 /* the element is itself an array */
691 namebuf = DMNEW(char, namelen + dim);
692 memcpy(namebuf + dim, ref->name->text, namelen);
696 /* the element is a non-array class */
697 namebuf = DMNEW(char, namelen + 2 + dim);
699 memcpy(namebuf + dim + 1, ref->name->text, namelen);
700 namelen += (2 + dim);
701 namebuf[namelen - 1] = ';';
703 memset(namebuf, '[', dim);
705 return class_get_classref(ref->referer,utf_new(namebuf, namelen));
709 /* class_get_classref_component_of *********************************************
711 Returns the component classref of a given array type reference
714 ref..............the array type reference
717 a reference to the component class, or
718 NULL if `ref` is not an object array type reference
721 The referer of `ref` is used as the referer for the new classref.
723 *******************************************************************************/
725 constant_classref *class_get_classref_component_of(constant_classref *ref)
732 name = ref->name->text;
736 namelen = ref->name->blength - 1;
741 else if (*name != '[') {
745 return class_get_classref(ref->referer, utf_new(name, namelen));
749 /* class_findmethod ************************************************************
751 Searches a 'classinfo' structure for a method having the given name
752 and descriptor. If descriptor is NULL, it is ignored.
754 *******************************************************************************/
756 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc)
761 for (i = 0; i < c->methodscount; i++) {
762 m = &(c->methods[i]);
764 if ((m->name == name) && ((desc == NULL) || (m->descriptor == desc)))
772 /* class_resolvemethod *********************************************************
774 Searches a class and it's super classes for a method.
776 Superinterfaces are *not* searched.
778 *******************************************************************************/
780 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *desc)
785 m = class_findmethod(c, name, desc);
790 /* JVM Specification bug:
792 It is important NOT to resolve special <init> and <clinit>
793 methods to super classes or interfaces; yet, this is not
794 explicited in the specification. Section 5.4.3.3 should be
795 updated appropriately. */
797 if (name == utf_init || name == utf_clinit)
807 /* class_resolveinterfacemethod_intern *****************************************
809 Internally used helper function. Do not use this directly.
811 *******************************************************************************/
813 static methodinfo *class_resolveinterfacemethod_intern(classinfo *c,
814 utf *name, utf *desc)
819 /* try to find the method in the class */
821 m = class_findmethod(c, name, desc);
826 /* no method found? try the superinterfaces */
828 for (i = 0; i < c->interfacescount; i++) {
829 m = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
836 /* no method found */
842 /* class_resolveclassmethod ****************************************************
844 Resolves a reference from REFERER to a method with NAME and DESC in
847 If the method cannot be resolved the return value is NULL. If
848 EXCEPT is true *exceptionptr is set, too.
850 *******************************************************************************/
852 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *desc,
853 classinfo *referer, bool throwexception)
859 /* if (c->flags & ACC_INTERFACE) { */
860 /* if (throwexception) */
861 /* *exceptionptr = */
862 /* new_exception(string_java_lang_IncompatibleClassChangeError); */
866 /* try class c and its superclasses */
870 m = class_resolvemethod(cls, name, desc);
875 /* try the superinterfaces */
877 for (i = 0; i < c->interfacescount; i++) {
878 m = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
886 exceptions_throw_nosuchmethoderror(c, name, desc);
891 if ((m->flags & ACC_ABSTRACT) && !(c->flags & ACC_ABSTRACT)) {
893 exceptions_throw_abstractmethoderror();
898 /* XXX check access rights */
904 /* class_resolveinterfacemethod ************************************************
906 Resolves a reference from REFERER to a method with NAME and DESC in
909 If the method cannot be resolved the return value is NULL. If
910 EXCEPT is true *exceptionptr is set, too.
912 *******************************************************************************/
914 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *desc,
915 classinfo *referer, bool throwexception)
919 if (!(c->flags & ACC_INTERFACE)) {
922 new_exception(string_java_lang_IncompatibleClassChangeError);
927 mi = class_resolveinterfacemethod_intern(c, name, desc);
932 /* try class java.lang.Object */
934 mi = class_findmethod(class_java_lang_Object, name, desc);
941 exceptions_new_nosuchmethoderror(c, name, desc);
947 /* class_findfield *************************************************************
949 Searches for field with specified name and type in a classinfo
950 structure. If no such field is found NULL is returned.
952 *******************************************************************************/
954 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc)
958 for (i = 0; i < c->fieldscount; i++)
959 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc))
960 return &(c->fields[i]);
963 return class_findfield(c->super.cls, name, desc);
969 /* class_findfield_approx ******************************************************
971 Searches in 'classinfo'-structure for a field with the specified
974 *******************************************************************************/
976 fieldinfo *class_findfield_by_name(classinfo *c, utf *name)
980 /* get field index */
982 i = class_findfield_index_by_name(c, name);
984 /* field was not found, return */
989 /* return field address */
991 return &(c->fields[i]);
995 s4 class_findfield_index_by_name(classinfo *c, utf *name)
999 for (i = 0; i < c->fieldscount; i++) {
1000 /* compare field names */
1002 if ((c->fields[i].name == name))
1006 /* field was not found, raise exception */
1008 *exceptionptr = new_exception(string_java_lang_NoSuchFieldException);
1014 /****************** Function: class_resolvefield_int ***************************
1016 This is an internally used helper function. Do not use this directly.
1018 Tries to resolve a field having the given name and type.
1019 If the field cannot be resolved, NULL is returned.
1021 *******************************************************************************/
1023 static fieldinfo *class_resolvefield_int(classinfo *c, utf *name, utf *desc)
1028 /* search for field in class c */
1030 for (i = 0; i < c->fieldscount; i++) {
1031 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc)) {
1032 return &(c->fields[i]);
1036 /* try superinterfaces recursively */
1038 for (i = 0; i < c->interfacescount; i++) {
1039 fi = class_resolvefield_int(c->interfaces[i].cls, name, desc);
1044 /* try superclass */
1047 return class_resolvefield_int(c->super.cls, name, desc);
1055 /********************* Function: class_resolvefield ***************************
1057 Resolves a reference from REFERER to a field with NAME and DESC in class C.
1059 If the field cannot be resolved the return value is NULL. If EXCEPT is
1060 true *exceptionptr is set, too.
1062 *******************************************************************************/
1064 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc,
1065 classinfo *referer, bool throwexception)
1069 fi = class_resolvefield_int(c, name, desc);
1074 new_exception_utfmessage(string_java_lang_NoSuchFieldError,
1080 /* XXX check access rights */
1086 /* class_issubclass ************************************************************
1088 Checks if sub is a descendant of super.
1090 *******************************************************************************/
1092 bool class_issubclass(classinfo *sub, classinfo *super)
1101 sub = sub->super.cls;
1106 /* class_printflags ************************************************************
1108 Prints flags of a class.
1110 *******************************************************************************/
1112 #if !defined(NDEBUG)
1113 void class_printflags(classinfo *c)
1120 if (c->flags & ACC_PUBLIC) printf(" PUBLIC");
1121 if (c->flags & ACC_PRIVATE) printf(" PRIVATE");
1122 if (c->flags & ACC_PROTECTED) printf(" PROTECTED");
1123 if (c->flags & ACC_STATIC) printf(" STATIC");
1124 if (c->flags & ACC_FINAL) printf(" FINAL");
1125 if (c->flags & ACC_SYNCHRONIZED) printf(" SYNCHRONIZED");
1126 if (c->flags & ACC_VOLATILE) printf(" VOLATILE");
1127 if (c->flags & ACC_TRANSIENT) printf(" TRANSIENT");
1128 if (c->flags & ACC_NATIVE) printf(" NATIVE");
1129 if (c->flags & ACC_INTERFACE) printf(" INTERFACE");
1130 if (c->flags & ACC_ABSTRACT) printf(" ABSTRACT");
1135 /* class_print *****************************************************************
1137 Prints classname plus flags.
1139 *******************************************************************************/
1141 #if !defined(NDEBUG)
1142 void class_print(classinfo *c)
1149 utf_display_printable_ascii(c->name);
1150 class_printflags(c);
1155 /* class_classref_print ********************************************************
1157 Prints classname plus referer class.
1159 *******************************************************************************/
1161 #if !defined(NDEBUG)
1162 void class_classref_print(constant_classref *cr)
1169 utf_display_printable_ascii(cr->name);
1172 class_print(cr->referer);
1180 /* class_println ***************************************************************
1182 Prints classname plus flags and new line.
1184 *******************************************************************************/
1186 #if !defined(NDEBUG)
1187 void class_println(classinfo *c)
1195 /* class_classref_println ******************************************************
1197 Prints classname plus referer class and new line.
1199 *******************************************************************************/
1201 #if !defined(NDEBUG)
1202 void class_classref_println(constant_classref *cr)
1204 class_classref_print(cr);
1210 /* class_showconstantpool ******************************************************
1212 Dump the constant pool of the given class to stdout.
1214 *******************************************************************************/
1216 #if !defined(NDEBUG)
1217 void class_showconstantpool (classinfo *c)
1222 printf ("---- dump of constant pool ----\n");
1224 for (i=0; i<c->cpcount; i++) {
1225 printf ("#%d: ", (int) i);
1227 e = c -> cpinfos [i];
1230 switch (c -> cptags [i]) {
1231 case CONSTANT_Class:
1232 printf ("Classreference -> ");
1233 utf_display_printable_ascii ( ((constant_classref*)e) -> name );
1235 case CONSTANT_Fieldref:
1236 printf ("Fieldref -> ");
1237 field_fieldref_print((constant_FMIref *) e);
1239 case CONSTANT_Methodref:
1240 printf ("Methodref -> ");
1241 method_methodref_print((constant_FMIref *) e);
1243 case CONSTANT_InterfaceMethodref:
1244 printf ("InterfaceMethod -> ");
1245 method_methodref_print((constant_FMIref *) e);
1247 case CONSTANT_String:
1248 printf ("String -> ");
1249 utf_display_printable_ascii (e);
1251 case CONSTANT_Integer:
1252 printf ("Integer -> %d", (int) ( ((constant_integer*)e) -> value) );
1254 case CONSTANT_Float:
1255 printf ("Float -> %f", ((constant_float*)e) -> value);
1257 case CONSTANT_Double:
1258 printf ("Double -> %f", ((constant_double*)e) -> value);
1262 u8 v = ((constant_long*)e) -> value;
1264 printf ("Long -> %ld", (long int) v);
1266 printf ("Long -> HI: %ld, LO: %ld\n",
1267 (long int) v.high, (long int) v.low);
1271 case CONSTANT_NameAndType:
1273 constant_nameandtype *cnt = e;
1274 printf ("NameAndType: ");
1275 utf_display_printable_ascii (cnt->name);
1277 utf_display_printable_ascii (cnt->descriptor);
1281 printf ("Utf8 -> ");
1282 utf_display_printable_ascii (e);
1285 log_text("Invalid type of ConstantPool-Entry");
1293 #endif /* !defined(NDEBUG) */
1296 /* class_showmethods ***********************************************************
1298 Dump info about the fields and methods of the given class to stdout.
1300 *******************************************************************************/
1302 #if !defined(NDEBUG)
1303 void class_showmethods (classinfo *c)
1307 printf("--------- Fields and Methods ----------------\n");
1309 class_printflags(c);
1313 utf_display_printable_ascii(c->name);
1318 utf_display_printable_ascii(c->super.cls->name);
1322 printf("Index: %d\n", c->index);
1324 printf("Interfaces:\n");
1325 for (i = 0; i < c->interfacescount; i++) {
1327 utf_display_printable_ascii(c->interfaces[i].cls->name);
1328 printf (" (%d)\n", c->interfaces[i].cls->index);
1331 printf("Fields:\n");
1332 for (i = 0; i < c->fieldscount; i++)
1333 field_println(&(c->fields[i]));
1335 printf("Methods:\n");
1336 for (i = 0; i < c->methodscount; i++) {
1337 methodinfo *m = &(c->methods[i]);
1339 if (!(m->flags & ACC_STATIC))
1340 printf("vftblindex: %d ", m->vftblindex);
1345 printf ("Virtual function table:\n");
1346 for (i = 0; i < c->vftbl->vftbllength; i++)
1347 printf ("entry: %d, %ld\n", i, (long int) (c->vftbl->table[i]));
1349 #endif /* !defined(NDEBUG) */
1353 * These are local overrides for various environment variables in Emacs.
1354 * Please do not remove this and leave it at the end of the file, where
1355 * Emacs will automagically detect them.
1356 * ---------------------------------------------------------------------
1359 * indent-tabs-mode: t
1363 * vim:noexpandtab:sw=4:ts=4: