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 5250 2006-08-18 12:24:10Z 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_VMSystem;
101 classinfo *class_java_lang_VMThread;
102 classinfo *class_java_io_Serializable;
105 /* system exception classes required in cacao */
107 classinfo *class_java_lang_Throwable;
108 classinfo *class_java_lang_VMThrowable;
109 classinfo *class_java_lang_Error;
110 classinfo *class_java_lang_AbstractMethodError;
111 classinfo *class_java_lang_LinkageError;
112 classinfo *class_java_lang_NoClassDefFoundError;
113 classinfo *class_java_lang_NoSuchMethodError;
114 classinfo *class_java_lang_OutOfMemoryError;
116 classinfo *class_java_lang_Exception;
117 classinfo *class_java_lang_ClassCastException;
118 classinfo *class_java_lang_ClassNotFoundException;
119 classinfo *class_java_lang_IllegalArgumentException;
120 classinfo *class_java_lang_IllegalMonitorStateException;
122 classinfo *class_java_lang_Void;
123 classinfo *class_java_lang_Boolean;
124 classinfo *class_java_lang_Byte;
125 classinfo *class_java_lang_Character;
126 classinfo *class_java_lang_Short;
127 classinfo *class_java_lang_Integer;
128 classinfo *class_java_lang_Long;
129 classinfo *class_java_lang_Float;
130 classinfo *class_java_lang_Double;
133 /* some runtime exception */
135 classinfo *class_java_lang_NullPointerException;
138 /* some classes which may be used more often */
140 classinfo *class_java_lang_StackTraceElement;
141 classinfo *class_java_lang_reflect_Constructor;
142 classinfo *class_java_lang_reflect_Field;
143 classinfo *class_java_lang_reflect_Method;
144 classinfo *class_java_security_PrivilegedAction;
145 classinfo *class_java_util_Vector;
147 classinfo *arrayclass_java_lang_Object;
150 /* pseudo classes for the typechecker */
152 classinfo *pseudo_class_Arraystub;
153 classinfo *pseudo_class_Null;
154 classinfo *pseudo_class_New;
157 /* class_set_packagename *******************************************************
159 Derive the package name from the class name and store it in the struct.
161 *******************************************************************************/
163 void class_set_packagename(classinfo *c)
165 char *p = UTF_END(c->name) - 1;
166 char *start = c->name->text;
168 /* set the package name */
169 /* classes in the unnamed package keep packagename == NULL */
171 if (c->name->text[0] == '[') {
172 /* set packagename of arrays to the element's package */
174 for (; *start == '['; start++);
176 /* skip the 'L' in arrays of references */
180 for (; (p > start) && (*p != '/'); --p);
182 c->packagename = utf_new(start, p - start);
185 for (; (p > start) && (*p != '/'); --p);
187 c->packagename = utf_new(start, p - start);
192 /* class_create_classinfo ******************************************************
194 Create a new classinfo struct. The class name is set to the given utf *,
195 most other fields are initialized to zero.
197 Note: classname may be NULL. In this case a not-yet-named classinfo is
198 created. The name must be filled in later and class_set_packagename
199 must be called after that.
201 *******************************************************************************/
203 classinfo *class_create_classinfo(utf *classname)
207 #if defined(ENABLE_STATISTICS)
209 size_classinfo += sizeof(classinfo);
212 /* we use a safe name for temporarily unnamed classes */
214 classname = utf_not_named_yet;
218 log_message_utf("Creating class: ", classname);
221 /* GCNEW_UNCOLLECTABLE clears the allocated memory */
223 c = GCNEW_UNCOLLECTABLE(classinfo, 1);
224 /*c=NEW(classinfo);*/
227 /* set the header.vftbl of all loaded classes to the one of
228 java.lang.Class, so Java code can use a class as object */
230 if (class_java_lang_Class)
231 if (class_java_lang_Class->vftbl)
232 c->object.header.vftbl = class_java_lang_Class->vftbl;
234 if (classname != utf_not_named_yet)
235 class_set_packagename(c);
237 #if defined(ENABLE_THREADS)
238 lock_init_object_lock(&c->object.header);
245 /* class_postset_header_vftbl **************************************************
247 Set the header.vftbl of all classes created before java.lang.Class
248 was linked. This is necessary that Java code can use a class as
251 *******************************************************************************/
253 void class_postset_header_vftbl(void)
257 classcache_name_entry *nmen;
258 classcache_class_entry *clsen;
260 assert(class_java_lang_Class);
262 for (slot = 0; slot < hashtable_classcache.size; slot++) {
263 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
265 for (; nmen; nmen = nmen->hashlink) {
266 /* iterate over all class entries */
268 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
271 /* now set the the vftbl */
273 if (c->object.header.vftbl == NULL)
274 c->object.header.vftbl = class_java_lang_Class->vftbl;
281 /* class_freepool **************************************************************
283 Frees all resources used by this classes Constant Pool.
285 *******************************************************************************/
287 static void class_freecpool(classinfo *c)
293 if (c->cptags && c->cpinfos) {
294 for (idx = 0; idx < c->cpcount; idx++) {
295 tag = c->cptags[idx];
296 info = c->cpinfos[idx];
300 case CONSTANT_Fieldref:
301 case CONSTANT_Methodref:
302 case CONSTANT_InterfaceMethodref:
303 FREE(info, constant_FMIref);
305 case CONSTANT_Integer:
306 FREE(info, constant_integer);
309 FREE(info, constant_float);
312 FREE(info, constant_long);
314 case CONSTANT_Double:
315 FREE(info, constant_double);
317 case CONSTANT_NameAndType:
318 FREE(info, constant_nameandtype);
326 MFREE(c->cptags, u1, c->cpcount);
329 MFREE(c->cpinfos, voidptr, c->cpcount);
333 /* class_getconstant ***********************************************************
335 Retrieves the value at position 'pos' of the constantpool of a
336 class. If the type of the value is other than 'ctype', an error is
339 *******************************************************************************/
341 voidptr class_getconstant(classinfo *c, u4 pos, u4 ctype)
343 /* check index and type of constantpool entry */
344 /* (pos == 0 is caught by type comparison) */
346 if (pos >= c->cpcount || c->cptags[pos] != ctype) {
347 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
351 return c->cpinfos[pos];
355 /* innerclass_getconstant ******************************************************
357 Like class_getconstant, but if cptags is ZERO, null is returned.
359 *******************************************************************************/
361 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype)
363 /* invalid position in constantpool */
364 if (pos >= c->cpcount) {
365 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
369 /* constantpool entry of type 0 */
373 /* check type of constantpool entry */
374 if (c->cptags[pos] != ctype) {
375 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
379 return c->cpinfos[pos];
383 /* class_free ******************************************************************
385 Frees all resources used by the class.
387 *******************************************************************************/
389 void class_free(classinfo *c)
397 MFREE(c->interfaces, classinfo*, c->interfacescount);
400 for (i = 0; i < c->fieldscount; i++)
401 field_free(&(c->fields[i]));
402 /* MFREE(c->fields, fieldinfo, c->fieldscount); */
406 for (i = 0; i < c->methodscount; i++)
407 method_free(&(c->methods[i]));
408 MFREE(c->methods, methodinfo, c->methodscount);
411 if ((v = c->vftbl) != NULL) {
413 mem_free(v->arraydesc,sizeof(arraydescriptor));
415 for (i = 0; i < v->interfacetablelength; i++) {
416 MFREE(v->interfacetable[-i], methodptr, v->interfacevftbllength[i]);
418 MFREE(v->interfacevftbllength, s4, v->interfacetablelength);
420 i = sizeof(vftbl_t) + sizeof(methodptr) * (v->vftbllength - 1) +
421 sizeof(methodptr*) * (v->interfacetablelength -
422 (v->interfacetablelength > 0));
423 v = (vftbl_t*) (((methodptr*) v) -
424 (v->interfacetablelength - 1) * (v->interfacetablelength > 1));
429 MFREE(c->innerclass, innerclassinfo, c->innerclasscount);
431 /* if (c->classvftbl)
432 mem_free(c->header.vftbl, sizeof(vftbl) + sizeof(methodptr)*(c->vftbl->vftbllength-1)); */
438 /* get_array_class *************************************************************
440 Returns the array class with the given name for the given
441 classloader, or NULL if an exception occurred.
443 Note: This function does eager loading.
445 *******************************************************************************/
447 static classinfo *get_array_class(utf *name,java_objectheader *initloader,
448 java_objectheader *defloader,bool link)
452 /* lookup this class in the classcache */
453 c = classcache_lookup(initloader,name);
455 c = classcache_lookup_defined(defloader,name);
458 /* we have to create it */
459 c = class_create_classinfo(name);
460 c = load_newly_created_array(c,initloader);
466 CLASS_ASSERT(c->state & CLASS_LOADED);
467 CLASS_ASSERT(c->classloader == defloader);
469 if (link && !(c->state & CLASS_LINKED))
473 CLASS_ASSERT(!link || (c->state & CLASS_LINKED));
479 /* class_array_of **************************************************************
481 Returns an array class with the given component class. The array
482 class is dynamically created if neccessary.
484 *******************************************************************************/
486 classinfo *class_array_of(classinfo *component, bool link)
491 /* Assemble the array class name */
492 namelen = component->name->blength;
494 if (component->name->text[0] == '[') {
495 /* the component is itself an array */
496 namebuf = DMNEW(char, namelen + 1);
498 MCOPY(namebuf + 1, component->name->text, char, namelen);
502 /* the component is a non-array class */
503 namebuf = DMNEW(char, namelen + 3);
506 MCOPY(namebuf + 2, component->name->text, char, namelen);
507 namebuf[2 + namelen] = ';';
511 return get_array_class(utf_new(namebuf, namelen),
512 component->classloader,
513 component->classloader,
518 /* class_multiarray_of *********************************************************
520 Returns an array class with the given dimension and element class.
521 The array class is dynamically created if neccessary.
523 *******************************************************************************/
525 classinfo *class_multiarray_of(s4 dim, classinfo *element, bool link)
531 log_text("Invalid array dimension requested");
535 /* Assemble the array class name */
536 namelen = element->name->blength;
538 if (element->name->text[0] == '[') {
539 /* the element is itself an array */
540 namebuf = DMNEW(char, namelen + dim);
541 memcpy(namebuf + dim, element->name->text, namelen);
545 /* the element is a non-array class */
546 namebuf = DMNEW(char, namelen + 2 + dim);
548 memcpy(namebuf + dim + 1, element->name->text, namelen);
549 namelen += (2 + dim);
550 namebuf[namelen - 1] = ';';
552 memset(namebuf, '[', dim);
554 return get_array_class(utf_new(namebuf, namelen),
555 element->classloader,
556 element->classloader,
561 /* class_lookup_classref *******************************************************
563 Looks up the constant_classref for a given classname in the classref
567 cls..............the class containing the reference
568 name.............the name of the class refered to
571 a pointer to a constant_classref, or
572 NULL if the reference was not found
574 *******************************************************************************/
576 constant_classref *class_lookup_classref(classinfo *cls, utf *name)
578 constant_classref *ref;
579 extra_classref *xref;
584 CLASS_ASSERT(!cls->classrefcount || cls->classrefs);
586 /* first search the main classref table */
587 count = cls->classrefcount;
588 ref = cls->classrefs;
589 for (; count; --count, ++ref)
590 if (ref->name == name)
593 /* next try the list of extra classrefs */
594 for (xref = cls->extclassrefs; xref; xref = xref->next) {
595 if (xref->classref.name == name)
596 return &(xref->classref);
604 /* class_get_classref **********************************************************
606 Returns the constant_classref for a given classname.
609 cls..............the class containing the reference
610 name.............the name of the class refered to
613 a pointer to a constant_classref (never NULL)
616 The given name is not checked for validity!
618 *******************************************************************************/
620 constant_classref *class_get_classref(classinfo *cls, utf *name)
622 constant_classref *ref;
623 extra_classref *xref;
628 ref = class_lookup_classref(cls,name);
632 xref = NEW(extra_classref);
633 CLASSREF_INIT(xref->classref,cls,name);
635 xref->next = cls->extclassrefs;
636 cls->extclassrefs = xref;
638 return &(xref->classref);
642 /* class_get_self_classref *****************************************************
644 Returns the constant_classref to the class itself.
647 cls..............the class containing the reference
650 a pointer to a constant_classref (never NULL)
652 *******************************************************************************/
654 constant_classref *class_get_self_classref(classinfo *cls)
656 /* XXX this should be done in a faster way. Maybe always make */
657 /* the classref of index 0 a self reference. */
658 return class_get_classref(cls,cls->name);
661 /* class_get_classref_multiarray_of ********************************************
663 Returns an array type reference with the given dimension and element class
667 dim..............the requested dimension
668 dim must be in [1;255]. This is NOT checked!
669 ref..............the component class reference
672 a pointer to the class reference for the array type
675 The referer of `ref` is used as the referer for the new classref.
677 *******************************************************************************/
679 constant_classref *class_get_classref_multiarray_of(s4 dim, constant_classref *ref)
685 CLASS_ASSERT(dim >= 1 && dim <= 255);
687 /* Assemble the array class name */
688 namelen = ref->name->blength;
690 if (ref->name->text[0] == '[') {
691 /* the element is itself an array */
692 namebuf = DMNEW(char, namelen + dim);
693 memcpy(namebuf + dim, ref->name->text, namelen);
697 /* the element is a non-array class */
698 namebuf = DMNEW(char, namelen + 2 + dim);
700 memcpy(namebuf + dim + 1, ref->name->text, namelen);
701 namelen += (2 + dim);
702 namebuf[namelen - 1] = ';';
704 memset(namebuf, '[', dim);
706 return class_get_classref(ref->referer,utf_new(namebuf, namelen));
710 /* class_get_classref_component_of *********************************************
712 Returns the component classref of a given array type reference
715 ref..............the array type reference
718 a reference to the component class, or
719 NULL if `ref` is not an object array type reference
722 The referer of `ref` is used as the referer for the new classref.
724 *******************************************************************************/
726 constant_classref *class_get_classref_component_of(constant_classref *ref)
733 name = ref->name->text;
737 namelen = ref->name->blength - 1;
742 else if (*name != '[') {
746 return class_get_classref(ref->referer, utf_new(name, namelen));
750 /* class_findmethod ************************************************************
752 Searches a 'classinfo' structure for a method having the given name
753 and descriptor. If descriptor is NULL, it is ignored.
755 *******************************************************************************/
757 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc)
762 for (i = 0; i < c->methodscount; i++) {
763 m = &(c->methods[i]);
765 if ((m->name == name) && ((desc == NULL) || (m->descriptor == desc)))
773 /* class_resolvemethod *********************************************************
775 Searches a class and it's super classes for a method.
777 Superinterfaces are *not* searched.
779 *******************************************************************************/
781 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *desc)
786 m = class_findmethod(c, name, desc);
791 /* JVM Specification bug:
793 It is important NOT to resolve special <init> and <clinit>
794 methods to super classes or interfaces; yet, this is not
795 explicited in the specification. Section 5.4.3.3 should be
796 updated appropriately. */
798 if (name == utf_init || name == utf_clinit)
808 /* class_resolveinterfacemethod_intern *****************************************
810 Internally used helper function. Do not use this directly.
812 *******************************************************************************/
814 static methodinfo *class_resolveinterfacemethod_intern(classinfo *c,
815 utf *name, utf *desc)
820 /* try to find the method in the class */
822 m = class_findmethod(c, name, desc);
827 /* no method found? try the superinterfaces */
829 for (i = 0; i < c->interfacescount; i++) {
830 m = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
837 /* no method found */
843 /* class_resolveclassmethod ****************************************************
845 Resolves a reference from REFERER to a method with NAME and DESC in
848 If the method cannot be resolved the return value is NULL. If
849 EXCEPT is true *exceptionptr is set, too.
851 *******************************************************************************/
853 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *desc,
854 classinfo *referer, bool throwexception)
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 exceptions_throw_nosuchmethoderror(c, name, desc);
892 if ((m->flags & ACC_ABSTRACT) && !(c->flags & ACC_ABSTRACT)) {
894 exceptions_throw_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 if (!(c->flags & ACC_INTERFACE)) {
923 new_exception(string_java_lang_IncompatibleClassChangeError);
928 mi = class_resolveinterfacemethod_intern(c, name, desc);
933 /* try class java.lang.Object */
935 mi = class_findmethod(class_java_lang_Object, name, desc);
942 exceptions_new_nosuchmethoderror(c, name, desc);
948 /* class_findfield *************************************************************
950 Searches for field with specified name and type in a classinfo
951 structure. If no such field is found NULL is returned.
953 *******************************************************************************/
955 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc)
959 for (i = 0; i < c->fieldscount; i++)
960 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc))
961 return &(c->fields[i]);
964 return class_findfield(c->super.cls, name, desc);
970 /* class_findfield_approx ******************************************************
972 Searches in 'classinfo'-structure for a field with the specified
975 *******************************************************************************/
977 fieldinfo *class_findfield_by_name(classinfo *c, utf *name)
981 /* get field index */
983 i = class_findfield_index_by_name(c, name);
985 /* field was not found, return */
990 /* return field address */
992 return &(c->fields[i]);
996 s4 class_findfield_index_by_name(classinfo *c, utf *name)
1000 for (i = 0; i < c->fieldscount; i++) {
1001 /* compare field names */
1003 if ((c->fields[i].name == name))
1007 /* field was not found, raise exception */
1009 *exceptionptr = new_exception(string_java_lang_NoSuchFieldException);
1015 /****************** Function: class_resolvefield_int ***************************
1017 This is an internally used helper function. Do not use this directly.
1019 Tries to resolve a field having the given name and type.
1020 If the field cannot be resolved, NULL is returned.
1022 *******************************************************************************/
1024 static fieldinfo *class_resolvefield_int(classinfo *c, utf *name, utf *desc)
1029 /* search for field in class c */
1031 for (i = 0; i < c->fieldscount; i++) {
1032 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc)) {
1033 return &(c->fields[i]);
1037 /* try superinterfaces recursively */
1039 for (i = 0; i < c->interfacescount; i++) {
1040 fi = class_resolvefield_int(c->interfaces[i].cls, name, desc);
1045 /* try superclass */
1048 return class_resolvefield_int(c->super.cls, name, desc);
1056 /********************* Function: class_resolvefield ***************************
1058 Resolves a reference from REFERER to a field with NAME and DESC in class C.
1060 If the field cannot be resolved the return value is NULL. If EXCEPT is
1061 true *exceptionptr is set, too.
1063 *******************************************************************************/
1065 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc,
1066 classinfo *referer, bool throwexception)
1070 fi = class_resolvefield_int(c, name, desc);
1075 new_exception_utfmessage(string_java_lang_NoSuchFieldError,
1081 /* XXX check access rights */
1087 /* class_issubclass ************************************************************
1089 Checks if sub is a descendant of super.
1091 *******************************************************************************/
1093 bool class_issubclass(classinfo *sub, classinfo *super)
1102 sub = sub->super.cls;
1107 /* class_printflags ************************************************************
1109 Prints flags of a class.
1111 *******************************************************************************/
1113 #if !defined(NDEBUG)
1114 void class_printflags(classinfo *c)
1121 if (c->flags & ACC_PUBLIC) printf(" PUBLIC");
1122 if (c->flags & ACC_PRIVATE) printf(" PRIVATE");
1123 if (c->flags & ACC_PROTECTED) printf(" PROTECTED");
1124 if (c->flags & ACC_STATIC) printf(" STATIC");
1125 if (c->flags & ACC_FINAL) printf(" FINAL");
1126 if (c->flags & ACC_SYNCHRONIZED) printf(" SYNCHRONIZED");
1127 if (c->flags & ACC_VOLATILE) printf(" VOLATILE");
1128 if (c->flags & ACC_TRANSIENT) printf(" TRANSIENT");
1129 if (c->flags & ACC_NATIVE) printf(" NATIVE");
1130 if (c->flags & ACC_INTERFACE) printf(" INTERFACE");
1131 if (c->flags & ACC_ABSTRACT) printf(" ABSTRACT");
1136 /* class_print *****************************************************************
1138 Prints classname plus flags.
1140 *******************************************************************************/
1142 #if !defined(NDEBUG)
1143 void class_print(classinfo *c)
1150 utf_display_printable_ascii(c->name);
1151 class_printflags(c);
1156 /* class_classref_print ********************************************************
1158 Prints classname plus referer class.
1160 *******************************************************************************/
1162 #if !defined(NDEBUG)
1163 void class_classref_print(constant_classref *cr)
1170 utf_display_printable_ascii(cr->name);
1173 class_print(cr->referer);
1181 /* class_println ***************************************************************
1183 Prints classname plus flags and new line.
1185 *******************************************************************************/
1187 #if !defined(NDEBUG)
1188 void class_println(classinfo *c)
1196 /* class_classref_println ******************************************************
1198 Prints classname plus referer class and new line.
1200 *******************************************************************************/
1202 #if !defined(NDEBUG)
1203 void class_classref_println(constant_classref *cr)
1205 class_classref_print(cr);
1211 /* class_showconstantpool ******************************************************
1213 Dump the constant pool of the given class to stdout.
1215 *******************************************************************************/
1217 #if !defined(NDEBUG)
1218 void class_showconstantpool (classinfo *c)
1223 printf ("---- dump of constant pool ----\n");
1225 for (i=0; i<c->cpcount; i++) {
1226 printf ("#%d: ", (int) i);
1228 e = c -> cpinfos [i];
1231 switch (c -> cptags [i]) {
1232 case CONSTANT_Class:
1233 printf ("Classreference -> ");
1234 utf_display_printable_ascii ( ((constant_classref*)e) -> name );
1236 case CONSTANT_Fieldref:
1237 printf ("Fieldref -> ");
1238 field_fieldref_print((constant_FMIref *) e);
1240 case CONSTANT_Methodref:
1241 printf ("Methodref -> ");
1242 method_methodref_print((constant_FMIref *) e);
1244 case CONSTANT_InterfaceMethodref:
1245 printf ("InterfaceMethod -> ");
1246 method_methodref_print((constant_FMIref *) e);
1248 case CONSTANT_String:
1249 printf ("String -> ");
1250 utf_display_printable_ascii (e);
1252 case CONSTANT_Integer:
1253 printf ("Integer -> %d", (int) ( ((constant_integer*)e) -> value) );
1255 case CONSTANT_Float:
1256 printf ("Float -> %f", ((constant_float*)e) -> value);
1258 case CONSTANT_Double:
1259 printf ("Double -> %f", ((constant_double*)e) -> value);
1263 u8 v = ((constant_long*)e) -> value;
1265 printf ("Long -> %ld", (long int) v);
1267 printf ("Long -> HI: %ld, LO: %ld\n",
1268 (long int) v.high, (long int) v.low);
1272 case CONSTANT_NameAndType:
1274 constant_nameandtype *cnt = e;
1275 printf ("NameAndType: ");
1276 utf_display_printable_ascii (cnt->name);
1278 utf_display_printable_ascii (cnt->descriptor);
1282 printf ("Utf8 -> ");
1283 utf_display_printable_ascii (e);
1286 log_text("Invalid type of ConstantPool-Entry");
1294 #endif /* !defined(NDEBUG) */
1297 /* class_showmethods ***********************************************************
1299 Dump info about the fields and methods of the given class to stdout.
1301 *******************************************************************************/
1303 #if !defined(NDEBUG)
1304 void class_showmethods (classinfo *c)
1308 printf("--------- Fields and Methods ----------------\n");
1310 class_printflags(c);
1314 utf_display_printable_ascii(c->name);
1319 utf_display_printable_ascii(c->super.cls->name);
1323 printf("Index: %d\n", c->index);
1325 printf("Interfaces:\n");
1326 for (i = 0; i < c->interfacescount; i++) {
1328 utf_display_printable_ascii(c->interfaces[i].cls->name);
1329 printf (" (%d)\n", c->interfaces[i].cls->index);
1332 printf("Fields:\n");
1333 for (i = 0; i < c->fieldscount; i++)
1334 field_println(&(c->fields[i]));
1336 printf("Methods:\n");
1337 for (i = 0; i < c->methodscount; i++) {
1338 methodinfo *m = &(c->methods[i]);
1340 if (!(m->flags & ACC_STATIC))
1341 printf("vftblindex: %d ", m->vftblindex);
1346 printf ("Virtual function table:\n");
1347 for (i = 0; i < c->vftbl->vftbllength; i++)
1348 printf ("entry: %d, %ld\n", i, (long int) (c->vftbl->table[i]));
1350 #endif /* !defined(NDEBUG) */
1354 * These are local overrides for various environment variables in Emacs.
1355 * Please do not remove this and leave it at the end of the file, where
1356 * Emacs will automagically detect them.
1357 * ---------------------------------------------------------------------
1360 * indent-tabs-mode: t
1364 * vim:noexpandtab:sw=4:ts=4: