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
33 $Id: class.c 4582 2006-03-11 20:30:48Z edwin $
46 #include "mm/memory.h"
48 #if defined(USE_THREADS)
49 # if defined(NATIVE_THREADS)
50 # include "threads/native/threads.h"
52 # include "threads/green/threads.h"
53 # include "threads/green/locks.h"
57 #include "toolbox/logging.h"
59 #include "vm/classcache.h"
60 #include "vm/exceptions.h"
61 #include "vm/global.h"
62 #include "vm/loader.h"
63 #include "vm/options.h"
64 #include "vm/resolve.h"
65 #include "vm/statistics.h"
66 #include "vm/stringlocal.h"
70 /******************************************************************************/
72 /******************************************************************************/
79 #define CLASS_ASSERT(cond) assert(cond)
81 #define CLASS_ASSERT(cond)
85 /* global variables ***********************************************************/
87 list unlinkedclasses; /* this is only used for eager class */
91 /* frequently used classes ****************************************************/
93 /* important system classes */
95 classinfo *class_java_lang_Object = NULL;
96 classinfo *class_java_lang_Class = NULL;
97 classinfo *class_java_lang_ClassLoader = NULL;
98 classinfo *class_java_lang_Cloneable = NULL;
99 classinfo *class_java_lang_SecurityManager = NULL;
100 classinfo *class_java_lang_String = NULL;
101 classinfo *class_java_lang_System = NULL;
102 classinfo *class_java_lang_Thread = NULL;
103 classinfo *class_java_lang_ThreadGroup = NULL;
104 classinfo *class_java_lang_VMThread = NULL;
105 classinfo *class_java_io_Serializable = NULL;
108 /* system exception classes required in cacao */
110 classinfo *class_java_lang_Throwable = NULL;
111 classinfo *class_java_lang_VMThrowable = NULL;
112 classinfo *class_java_lang_Error = NULL;
113 classinfo *class_java_lang_NoClassDefFoundError = NULL;
114 classinfo *class_java_lang_LinkageError = NULL;
115 classinfo *class_java_lang_NoSuchMethodError = NULL;
116 classinfo *class_java_lang_OutOfMemoryError = NULL;
118 classinfo *class_java_lang_Exception = NULL;
119 classinfo *class_java_lang_ClassNotFoundException = NULL;
120 classinfo *class_java_lang_IllegalArgumentException = NULL;
121 classinfo *class_java_lang_IllegalMonitorStateException = NULL;
123 classinfo *class_java_lang_Void = NULL;
124 classinfo *class_java_lang_Boolean = NULL;
125 classinfo *class_java_lang_Byte = NULL;
126 classinfo *class_java_lang_Character = NULL;
127 classinfo *class_java_lang_Short = NULL;
128 classinfo *class_java_lang_Integer = NULL;
129 classinfo *class_java_lang_Long = NULL;
130 classinfo *class_java_lang_Float = NULL;
131 classinfo *class_java_lang_Double = NULL;
134 /* some runtime exception */
136 classinfo *class_java_lang_NullPointerException = NULL;
139 /* some classes which may be used more often */
141 classinfo *class_java_lang_StackTraceElement = NULL;
142 classinfo *class_java_lang_reflect_Constructor = NULL;
143 classinfo *class_java_lang_reflect_Field = NULL;
144 classinfo *class_java_lang_reflect_Method = NULL;
145 classinfo *class_java_security_PrivilegedAction = NULL;
146 classinfo *class_java_util_Vector = NULL;
148 classinfo *arrayclass_java_lang_Object = NULL;
151 /* pseudo classes for the typechecker */
153 classinfo *pseudo_class_Arraystub = NULL;
154 classinfo *pseudo_class_Null = NULL;
155 classinfo *pseudo_class_New = NULL;
158 /* class_set_packagename *******************************************************
160 Derive the package name from the class name and store it in the struct.
162 *******************************************************************************/
164 void class_set_packagename(classinfo *c)
166 char *p = UTF_END(c->name) - 1;
167 char *start = c->name->text;
169 /* set the package name */
170 /* classes in the unnamed package keep packagename == NULL */
172 if (c->name->text[0] == '[') {
173 /* set packagename of arrays to the element's package */
175 for (; *start == '['; start++);
177 /* skip the 'L' in arrays of references */
181 for (; (p > start) && (*p != '/'); --p);
183 c->packagename = utf_new(start, p - start);
186 for (; (p > start) && (*p != '/'); --p);
188 c->packagename = utf_new(start, p - start);
193 /* class_create_classinfo ******************************************************
195 Create a new classinfo struct. The class name is set to the given utf *,
196 most other fields are initialized to zero.
198 Note: classname may be NULL. In this case a not-yet-named classinfo is
199 created. The name must be filled in later and class_set_packagename
200 must be called after that.
202 *******************************************************************************/
204 classinfo *class_create_classinfo(utf *classname)
208 #if defined(ENABLE_STATISTICS)
210 count_class_infos += sizeof(classinfo);
213 /* we use a safe name for temporarily unnamed classes */
215 classname = utf_not_named_yet;
219 log_message_utf("Creating class: ", classname);
222 /* GCNEW_UNCOLLECTABLE clears the allocated memory */
224 c = GCNEW_UNCOLLECTABLE(classinfo, 1);
225 /*c=NEW(classinfo);*/
228 /* set the header.vftbl of all loaded classes to the one of
229 java.lang.Class, so Java code can use a class as object */
231 if (class_java_lang_Class)
232 if (class_java_lang_Class->vftbl)
233 c->object.header.vftbl = class_java_lang_Class->vftbl;
235 if (classname != utf_not_named_yet)
236 class_set_packagename(c);
238 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
239 initObjectLock(&c->object.header);
246 /* class_postset_header_vftbl **************************************************
248 Set the header.vftbl of all classes created before java.lang.Class
249 was linked. This is necessary that Java code can use a class as
252 *******************************************************************************/
254 void class_postset_header_vftbl(void)
258 classcache_name_entry *nmen;
259 classcache_class_entry *clsen;
261 assert(class_java_lang_Class);
263 for (slot = 0; slot < hashtable_classcache.size; slot++) {
264 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
266 for (; nmen; nmen = nmen->hashlink) {
267 /* iterate over all class entries */
269 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
272 /* now set the the vftbl */
274 if (c->object.header.vftbl == NULL)
275 c->object.header.vftbl = class_java_lang_Class->vftbl;
282 /* class_freepool **************************************************************
284 Frees all resources used by this classes Constant Pool.
286 *******************************************************************************/
288 static void class_freecpool(classinfo *c)
294 if (c->cptags && c->cpinfos) {
295 for (idx = 0; idx < c->cpcount; idx++) {
296 tag = c->cptags[idx];
297 info = c->cpinfos[idx];
301 case CONSTANT_Fieldref:
302 case CONSTANT_Methodref:
303 case CONSTANT_InterfaceMethodref:
304 FREE(info, constant_FMIref);
306 case CONSTANT_Integer:
307 FREE(info, constant_integer);
310 FREE(info, constant_float);
313 FREE(info, constant_long);
315 case CONSTANT_Double:
316 FREE(info, constant_double);
318 case CONSTANT_NameAndType:
319 FREE(info, constant_nameandtype);
327 MFREE(c->cptags, u1, c->cpcount);
330 MFREE(c->cpinfos, voidptr, c->cpcount);
334 /* class_getconstant ***********************************************************
336 Retrieves the value at position 'pos' of the constantpool of a
337 class. If the type of the value is other than 'ctype', an error is
340 *******************************************************************************/
342 voidptr class_getconstant(classinfo *c, u4 pos, u4 ctype)
344 /* check index and type of constantpool entry */
345 /* (pos == 0 is caught by type comparison) */
347 if (pos >= c->cpcount || c->cptags[pos] != ctype) {
348 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
352 return c->cpinfos[pos];
356 /* innerclass_getconstant ******************************************************
358 Like class_getconstant, but if cptags is ZERO, null is returned.
360 *******************************************************************************/
362 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype)
364 /* invalid position in constantpool */
365 if (pos >= c->cpcount) {
366 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
370 /* constantpool entry of type 0 */
374 /* check type of constantpool entry */
375 if (c->cptags[pos] != ctype) {
376 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
380 return c->cpinfos[pos];
384 /* class_free ******************************************************************
386 Frees all resources used by the class.
388 *******************************************************************************/
390 void class_free(classinfo *c)
398 MFREE(c->interfaces, classinfo*, c->interfacescount);
401 for (i = 0; i < c->fieldscount; i++)
402 field_free(&(c->fields[i]));
403 /* MFREE(c->fields, fieldinfo, c->fieldscount); */
407 for (i = 0; i < c->methodscount; i++)
408 method_free(&(c->methods[i]));
409 MFREE(c->methods, methodinfo, c->methodscount);
412 if ((v = c->vftbl) != NULL) {
414 mem_free(v->arraydesc,sizeof(arraydescriptor));
416 for (i = 0; i < v->interfacetablelength; i++) {
417 MFREE(v->interfacetable[-i], methodptr, v->interfacevftbllength[i]);
419 MFREE(v->interfacevftbllength, s4, v->interfacetablelength);
421 i = sizeof(vftbl_t) + sizeof(methodptr) * (v->vftbllength - 1) +
422 sizeof(methodptr*) * (v->interfacetablelength -
423 (v->interfacetablelength > 0));
424 v = (vftbl_t*) (((methodptr*) v) -
425 (v->interfacetablelength - 1) * (v->interfacetablelength > 1));
430 MFREE(c->innerclass, innerclassinfo, c->innerclasscount);
432 /* if (c->classvftbl)
433 mem_free(c->header.vftbl, sizeof(vftbl) + sizeof(methodptr)*(c->vftbl->vftbllength-1)); */
439 /* get_array_class *************************************************************
441 Returns the array class with the given name for the given
442 classloader, or NULL if an exception occurred.
444 Note: This function does eager loading.
446 *******************************************************************************/
448 static classinfo *get_array_class(utf *name,java_objectheader *initloader,
449 java_objectheader *defloader,bool link)
453 /* lookup this class in the classcache */
454 c = classcache_lookup(initloader,name);
456 c = classcache_lookup_defined(defloader,name);
459 /* we have to create it */
460 c = class_create_classinfo(name);
461 c = load_newly_created_array(c,initloader);
467 CLASS_ASSERT(c->state & CLASS_LOADED);
468 CLASS_ASSERT(c->classloader == defloader);
470 if (link && !(c->state & CLASS_LINKED))
474 CLASS_ASSERT(!link || (c->state & CLASS_LINKED));
480 /* class_array_of **************************************************************
482 Returns an array class with the given component class. The array
483 class is dynamically created if neccessary.
485 *******************************************************************************/
487 classinfo *class_array_of(classinfo *component, bool link)
492 /* Assemble the array class name */
493 namelen = component->name->blength;
495 if (component->name->text[0] == '[') {
496 /* the component is itself an array */
497 namebuf = DMNEW(char, namelen + 1);
499 MCOPY(namebuf + 1, component->name->text, char, namelen);
503 /* the component is a non-array class */
504 namebuf = DMNEW(char, namelen + 3);
507 MCOPY(namebuf + 2, component->name->text, char, namelen);
508 namebuf[2 + namelen] = ';';
512 return get_array_class(utf_new(namebuf, namelen),
513 component->classloader,
514 component->classloader,
519 /* class_multiarray_of *********************************************************
521 Returns an array class with the given dimension and element class.
522 The array class is dynamically created if neccessary.
524 *******************************************************************************/
526 classinfo *class_multiarray_of(s4 dim, classinfo *element, bool link)
532 log_text("Invalid array dimension requested");
536 /* Assemble the array class name */
537 namelen = element->name->blength;
539 if (element->name->text[0] == '[') {
540 /* the element is itself an array */
541 namebuf = DMNEW(char, namelen + dim);
542 memcpy(namebuf + dim, element->name->text, namelen);
546 /* the element is a non-array class */
547 namebuf = DMNEW(char, namelen + 2 + dim);
549 memcpy(namebuf + dim + 1, element->name->text, namelen);
550 namelen += (2 + dim);
551 namebuf[namelen - 1] = ';';
553 memset(namebuf, '[', dim);
555 return get_array_class(utf_new(namebuf, namelen),
556 element->classloader,
557 element->classloader,
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 CLASS_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)
686 CLASS_ASSERT(dim >= 1 && dim <= 255);
688 /* Assemble the array class name */
689 namelen = ref->name->blength;
691 if (ref->name->text[0] == '[') {
692 /* the element is itself an array */
693 namebuf = DMNEW(char, namelen + dim);
694 memcpy(namebuf + dim, ref->name->text, namelen);
698 /* the element is a non-array class */
699 namebuf = DMNEW(char, namelen + 2 + dim);
701 memcpy(namebuf + dim + 1, ref->name->text, namelen);
702 namelen += (2 + dim);
703 namebuf[namelen - 1] = ';';
705 memset(namebuf, '[', dim);
707 return class_get_classref(ref->referer,utf_new(namebuf, namelen));
711 /* class_get_classref_component_of *********************************************
713 Returns the component classref of a given array type reference
716 ref..............the array type reference
719 a reference to the component class, or
720 NULL if `ref` is not an object array type reference
723 The referer of `ref` is used as the referer for the new classref.
725 *******************************************************************************/
727 constant_classref *class_get_classref_component_of(constant_classref *ref)
734 name = ref->name->text;
738 namelen = ref->name->blength - 1;
743 else if (*name != '[') {
747 return class_get_classref(ref->referer, utf_new(name, namelen));
751 /* class_findmethod ************************************************************
753 Searches a 'classinfo' structure for a method having the given name
754 and descriptor. If descriptor is NULL, it is ignored.
756 *******************************************************************************/
758 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc)
763 for (i = 0; i < c->methodscount; i++) {
764 m = &(c->methods[i]);
766 if ((m->name == name) && ((desc == NULL) || (m->descriptor == desc)))
774 /* class_resolvemethod *********************************************************
776 Searches a class and it's super classes for a method.
778 Superinterfaces are *not* searched.
780 *******************************************************************************/
782 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *desc)
787 m = class_findmethod(c, name, desc);
792 /* JVM Specification bug:
794 It is important NOT to resolve special <init> and <clinit>
795 methods to super classes or interfaces; yet, this is not
796 explicited in the specification. Section 5.4.3.3 should be
797 updated appropriately. */
799 if (name == utf_init || name == utf_clinit)
809 /* class_resolveinterfacemethod_intern *****************************************
811 Internally used helper function. Do not use this directly.
813 *******************************************************************************/
815 static methodinfo *class_resolveinterfacemethod_intern(classinfo *c,
816 utf *name, utf *desc)
821 m = class_findmethod(c, name, desc);
826 /* try the superinterfaces */
828 for (i = 0; i < c->interfacescount; i++) {
829 m = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
840 /* class_resolveclassmethod ****************************************************
842 Resolves a reference from REFERER to a method with NAME and DESC in
845 If the method cannot be resolved the return value is NULL. If
846 EXCEPT is true *exceptionptr is set, too.
848 *******************************************************************************/
850 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *desc,
851 classinfo *referer, bool throwexception)
857 /* XXX resolve class c */
858 /* XXX check access from REFERER to C */
860 /* if (c->flags & ACC_INTERFACE) { */
861 /* if (throwexception) */
862 /* *exceptionptr = */
863 /* new_exception(string_java_lang_IncompatibleClassChangeError); */
867 /* try class c and its superclasses */
871 m = class_resolvemethod(cls, name, desc);
876 /* try the superinterfaces */
878 for (i = 0; i < c->interfacescount; i++) {
879 m = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
887 *exceptionptr = exceptions_new_nosuchmethoderror(c, name, desc);
892 if ((m->flags & ACC_ABSTRACT) && !(c->flags & ACC_ABSTRACT)) {
894 *exceptionptr = new_exception(string_java_lang_AbstractMethodError);
899 /* XXX check access rights */
905 /* class_resolveinterfacemethod ************************************************
907 Resolves a reference from REFERER to a method with NAME and DESC in
910 If the method cannot be resolved the return value is NULL. If
911 EXCEPT is true *exceptionptr is set, too.
913 *******************************************************************************/
915 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *desc,
916 classinfo *referer, bool throwexception)
920 /* XXX resolve class c */
921 /* XXX check access from REFERER to C */
923 if (!(c->flags & ACC_INTERFACE)) {
926 new_exception(string_java_lang_IncompatibleClassChangeError);
931 mi = class_resolveinterfacemethod_intern(c, name, desc);
936 /* try class java.lang.Object */
938 mi = class_findmethod(class_java_lang_Object, name, desc);
945 exceptions_new_nosuchmethoderror(c, name, desc);
951 /* class_findfield *************************************************************
953 Searches for field with specified name and type in a classinfo
954 structure. If no such field is found NULL is returned.
956 *******************************************************************************/
958 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc)
962 for (i = 0; i < c->fieldscount; i++)
963 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc))
964 return &(c->fields[i]);
967 return class_findfield(c->super.cls, name, desc);
973 /* class_findfield_approx ******************************************************
975 Searches in 'classinfo'-structure for a field with the specified
978 *******************************************************************************/
980 fieldinfo *class_findfield_by_name(classinfo *c, utf *name)
984 /* get field index */
986 i = class_findfield_index_by_name(c, name);
988 /* field was not found, return */
993 /* return field address */
995 return &(c->fields[i]);
999 s4 class_findfield_index_by_name(classinfo *c, utf *name)
1003 for (i = 0; i < c->fieldscount; i++) {
1004 /* compare field names */
1006 if ((c->fields[i].name == name))
1010 /* field was not found, raise exception */
1012 *exceptionptr = new_exception(string_java_lang_NoSuchFieldException);
1018 /****************** Function: class_resolvefield_int ***************************
1020 This is an internally used helper function. Do not use this directly.
1022 Tries to resolve a field having the given name and type.
1023 If the field cannot be resolved, NULL is returned.
1025 *******************************************************************************/
1027 static fieldinfo *class_resolvefield_int(classinfo *c, utf *name, utf *desc)
1032 /* search for field in class c */
1034 for (i = 0; i < c->fieldscount; i++) {
1035 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc)) {
1036 return &(c->fields[i]);
1040 /* try superinterfaces recursively */
1042 for (i = 0; i < c->interfacescount; i++) {
1043 fi = class_resolvefield_int(c->interfaces[i].cls, name, desc);
1048 /* try superclass */
1051 return class_resolvefield_int(c->super.cls, name, desc);
1059 /********************* Function: class_resolvefield ***************************
1061 Resolves a reference from REFERER to a field with NAME and DESC in class C.
1063 If the field cannot be resolved the return value is NULL. If EXCEPT is
1064 true *exceptionptr is set, too.
1066 *******************************************************************************/
1068 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc,
1069 classinfo *referer, bool throwexception)
1073 /* XXX resolve class c */
1074 /* XXX check access from REFERER to C */
1076 fi = class_resolvefield_int(c, name, desc);
1081 new_exception_utfmessage(string_java_lang_NoSuchFieldError,
1087 /* XXX check access rights */
1093 /* class_issubclass ************************************************************
1095 Checks if sub is a descendant of super.
1097 *******************************************************************************/
1099 bool class_issubclass(classinfo *sub, classinfo *super)
1108 sub = sub->super.cls;
1113 /* class_printflags ************************************************************
1115 Prints flags of a class.
1117 *******************************************************************************/
1119 #if !defined(NDEBUG)
1120 void class_printflags(classinfo *c)
1127 if (c->flags & ACC_PUBLIC) printf(" PUBLIC");
1128 if (c->flags & ACC_PRIVATE) printf(" PRIVATE");
1129 if (c->flags & ACC_PROTECTED) printf(" PROTECTED");
1130 if (c->flags & ACC_STATIC) printf(" STATIC");
1131 if (c->flags & ACC_FINAL) printf(" FINAL");
1132 if (c->flags & ACC_SYNCHRONIZED) printf(" SYNCHRONIZED");
1133 if (c->flags & ACC_VOLATILE) printf(" VOLATILE");
1134 if (c->flags & ACC_TRANSIENT) printf(" TRANSIENT");
1135 if (c->flags & ACC_NATIVE) printf(" NATIVE");
1136 if (c->flags & ACC_INTERFACE) printf(" INTERFACE");
1137 if (c->flags & ACC_ABSTRACT) printf(" ABSTRACT");
1142 /* class_print *****************************************************************
1144 Prints classname plus flags.
1146 *******************************************************************************/
1148 #if !defined(NDEBUG)
1149 void class_print(classinfo *c)
1156 utf_display(c->name);
1157 class_printflags(c);
1162 /* class_classref_print ********************************************************
1164 Prints classname plus referer class.
1166 *******************************************************************************/
1168 #if !defined(NDEBUG)
1169 void class_classref_print(constant_classref *cr)
1176 utf_display(cr->name);
1179 class_print(cr->referer);
1187 /* class_println ***************************************************************
1189 Prints classname plus flags and new line.
1191 *******************************************************************************/
1193 #if !defined(NDEBUG)
1194 void class_println(classinfo *c)
1202 /* class_classref_println ******************************************************
1204 Prints classname plus referer class and new line.
1206 *******************************************************************************/
1208 #if !defined(NDEBUG)
1209 void class_classref_println(constant_classref *cr)
1211 class_classref_print(cr);
1217 #if !defined(NDEBUG)
1218 void class_showconstanti(classinfo *c, int ii)
1224 printf ("#%d: ", (int) i);
1226 switch (c->cptags [i]) {
1227 case CONSTANT_Class:
1228 printf("Classreference -> ");
1229 utf_display(((constant_classref*)e)->name);
1232 case CONSTANT_Fieldref:
1233 printf("Fieldref -> "); goto displayFMIi;
1234 case CONSTANT_Methodref:
1235 printf("Methodref -> "); goto displayFMIi;
1236 case CONSTANT_InterfaceMethodref:
1237 printf("InterfaceMethod -> "); goto displayFMIi;
1240 constant_FMIref *fmi = e;
1241 utf_display(fmi->classref->name);
1243 utf_display(fmi->name);
1245 utf_display(fmi->descriptor);
1249 case CONSTANT_String:
1250 printf("String -> ");
1253 case CONSTANT_Integer:
1254 printf("Integer -> %d", (int) (((constant_integer*)e)->value));
1256 case CONSTANT_Float:
1257 printf("Float -> %f", ((constant_float*)e)->value);
1259 case CONSTANT_Double:
1260 printf("Double -> %f", ((constant_double*)e)->value);
1264 u8 v = ((constant_long*)e)->value;
1266 printf("Long -> %ld", (long int) v);
1268 printf("Long -> HI: %ld, LO: %ld\n",
1269 (long int) v.high, (long int) v.low);
1273 case CONSTANT_NameAndType:
1275 constant_nameandtype *cnt = e;
1276 printf("NameAndType: ");
1277 utf_display(cnt->name);
1279 utf_display(cnt->descriptor);
1287 log_text("Invalid type of ConstantPool-Entry");
1295 void class_showconstantpool (classinfo *c)
1300 printf ("---- dump of constant pool ----\n");
1302 for (i=0; i<c->cpcount; i++) {
1303 printf ("#%d: ", (int) i);
1305 e = c -> cpinfos [i];
1308 switch (c -> cptags [i]) {
1309 case CONSTANT_Class:
1310 printf ("Classreference -> ");
1311 utf_display ( ((constant_classref*)e) -> name );
1314 case CONSTANT_Fieldref:
1315 printf ("Fieldref -> "); goto displayFMI;
1316 case CONSTANT_Methodref:
1317 printf ("Methodref -> "); goto displayFMI;
1318 case CONSTANT_InterfaceMethodref:
1319 printf ("InterfaceMethod -> "); goto displayFMI;
1322 constant_FMIref *fmi = e;
1323 utf_display ( fmi->classref->name );
1325 utf_display ( fmi->name);
1327 utf_display ( fmi->descriptor );
1331 case CONSTANT_String:
1332 printf ("String -> ");
1335 case CONSTANT_Integer:
1336 printf ("Integer -> %d", (int) ( ((constant_integer*)e) -> value) );
1338 case CONSTANT_Float:
1339 printf ("Float -> %f", ((constant_float*)e) -> value);
1341 case CONSTANT_Double:
1342 printf ("Double -> %f", ((constant_double*)e) -> value);
1346 u8 v = ((constant_long*)e) -> value;
1348 printf ("Long -> %ld", (long int) v);
1350 printf ("Long -> HI: %ld, LO: %ld\n",
1351 (long int) v.high, (long int) v.low);
1355 case CONSTANT_NameAndType:
1357 constant_nameandtype *cnt = e;
1358 printf ("NameAndType: ");
1359 utf_display (cnt->name);
1361 utf_display (cnt->descriptor);
1365 printf ("Utf8 -> ");
1369 log_text("Invalid type of ConstantPool-Entry");
1380 /********** Function: class_showmethods (debugging only) *************/
1382 void class_showmethods (classinfo *c)
1386 printf("--------- Fields and Methods ----------------\n");
1388 class_printflags(c);
1392 utf_display(c->name);
1397 utf_display(c->super.cls->name);
1401 printf("Index: %d\n", c->index);
1403 printf("Interfaces:\n");
1404 for (i = 0; i < c->interfacescount; i++) {
1406 utf_display(c->interfaces[i].cls->name);
1407 printf (" (%d)\n", c->interfaces[i].cls->index);
1410 printf("Fields:\n");
1411 for (i = 0; i < c->fieldscount; i++)
1412 field_println(&(c->fields[i]));
1414 printf("Methods:\n");
1415 for (i = 0; i < c->methodscount; i++) {
1416 methodinfo *m = &(c->methods[i]);
1418 if (!(m->flags & ACC_STATIC))
1419 printf("vftblindex: %d ", m->vftblindex);
1424 printf ("Virtual function table:\n");
1425 for (i = 0; i < c->vftbl->vftbllength; i++)
1426 printf ("entry: %d, %ld\n", i, (long int) (c->vftbl->table[i]));
1428 #endif /* !defined(NDEBUG) */
1432 * These are local overrides for various environment variables in Emacs.
1433 * Please do not remove this and leave it at the end of the file, where
1434 * Emacs will automagically detect them.
1435 * ---------------------------------------------------------------------
1438 * indent-tabs-mode: t