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 5053 2006-06-28 19:11:20Z 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_ClassNotFoundException;
117 classinfo *class_java_lang_IllegalArgumentException;
118 classinfo *class_java_lang_IllegalMonitorStateException;
120 classinfo *class_java_lang_Void;
121 classinfo *class_java_lang_Boolean;
122 classinfo *class_java_lang_Byte;
123 classinfo *class_java_lang_Character;
124 classinfo *class_java_lang_Short;
125 classinfo *class_java_lang_Integer;
126 classinfo *class_java_lang_Long;
127 classinfo *class_java_lang_Float;
128 classinfo *class_java_lang_Double;
131 /* some runtime exception */
133 classinfo *class_java_lang_NullPointerException;
136 /* some classes which may be used more often */
138 classinfo *class_java_lang_StackTraceElement;
139 classinfo *class_java_lang_reflect_Constructor;
140 classinfo *class_java_lang_reflect_Field;
141 classinfo *class_java_lang_reflect_Method;
142 classinfo *class_java_security_PrivilegedAction;
143 classinfo *class_java_util_Vector;
145 classinfo *arrayclass_java_lang_Object;
148 /* pseudo classes for the typechecker */
150 classinfo *pseudo_class_Arraystub;
151 classinfo *pseudo_class_Null;
152 classinfo *pseudo_class_New;
155 /* class_set_packagename *******************************************************
157 Derive the package name from the class name and store it in the struct.
159 *******************************************************************************/
161 void class_set_packagename(classinfo *c)
163 char *p = UTF_END(c->name) - 1;
164 char *start = c->name->text;
166 /* set the package name */
167 /* classes in the unnamed package keep packagename == NULL */
169 if (c->name->text[0] == '[') {
170 /* set packagename of arrays to the element's package */
172 for (; *start == '['; start++);
174 /* skip the 'L' in arrays of references */
178 for (; (p > start) && (*p != '/'); --p);
180 c->packagename = utf_new(start, p - start);
183 for (; (p > start) && (*p != '/'); --p);
185 c->packagename = utf_new(start, p - start);
190 /* class_create_classinfo ******************************************************
192 Create a new classinfo struct. The class name is set to the given utf *,
193 most other fields are initialized to zero.
195 Note: classname may be NULL. In this case a not-yet-named classinfo is
196 created. The name must be filled in later and class_set_packagename
197 must be called after that.
199 *******************************************************************************/
201 classinfo *class_create_classinfo(utf *classname)
205 #if defined(ENABLE_STATISTICS)
207 count_class_infos += sizeof(classinfo);
210 /* we use a safe name for temporarily unnamed classes */
212 classname = utf_not_named_yet;
216 log_message_utf("Creating class: ", classname);
219 /* GCNEW_UNCOLLECTABLE clears the allocated memory */
221 c = GCNEW_UNCOLLECTABLE(classinfo, 1);
222 /*c=NEW(classinfo);*/
225 /* set the header.vftbl of all loaded classes to the one of
226 java.lang.Class, so Java code can use a class as object */
228 if (class_java_lang_Class)
229 if (class_java_lang_Class->vftbl)
230 c->object.header.vftbl = class_java_lang_Class->vftbl;
232 if (classname != utf_not_named_yet)
233 class_set_packagename(c);
235 #if defined(ENABLE_THREADS)
236 lock_init_object_lock(&c->object.header);
243 /* class_postset_header_vftbl **************************************************
245 Set the header.vftbl of all classes created before java.lang.Class
246 was linked. This is necessary that Java code can use a class as
249 *******************************************************************************/
251 void class_postset_header_vftbl(void)
255 classcache_name_entry *nmen;
256 classcache_class_entry *clsen;
258 assert(class_java_lang_Class);
260 for (slot = 0; slot < hashtable_classcache.size; slot++) {
261 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
263 for (; nmen; nmen = nmen->hashlink) {
264 /* iterate over all class entries */
266 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
269 /* now set the the vftbl */
271 if (c->object.header.vftbl == NULL)
272 c->object.header.vftbl = class_java_lang_Class->vftbl;
279 /* class_freepool **************************************************************
281 Frees all resources used by this classes Constant Pool.
283 *******************************************************************************/
285 static void class_freecpool(classinfo *c)
291 if (c->cptags && c->cpinfos) {
292 for (idx = 0; idx < c->cpcount; idx++) {
293 tag = c->cptags[idx];
294 info = c->cpinfos[idx];
298 case CONSTANT_Fieldref:
299 case CONSTANT_Methodref:
300 case CONSTANT_InterfaceMethodref:
301 FREE(info, constant_FMIref);
303 case CONSTANT_Integer:
304 FREE(info, constant_integer);
307 FREE(info, constant_float);
310 FREE(info, constant_long);
312 case CONSTANT_Double:
313 FREE(info, constant_double);
315 case CONSTANT_NameAndType:
316 FREE(info, constant_nameandtype);
324 MFREE(c->cptags, u1, c->cpcount);
327 MFREE(c->cpinfos, voidptr, c->cpcount);
331 /* class_getconstant ***********************************************************
333 Retrieves the value at position 'pos' of the constantpool of a
334 class. If the type of the value is other than 'ctype', an error is
337 *******************************************************************************/
339 voidptr class_getconstant(classinfo *c, u4 pos, u4 ctype)
341 /* check index and type of constantpool entry */
342 /* (pos == 0 is caught by type comparison) */
344 if (pos >= c->cpcount || c->cptags[pos] != ctype) {
345 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
349 return c->cpinfos[pos];
353 /* innerclass_getconstant ******************************************************
355 Like class_getconstant, but if cptags is ZERO, null is returned.
357 *******************************************************************************/
359 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype)
361 /* invalid position in constantpool */
362 if (pos >= c->cpcount) {
363 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
367 /* constantpool entry of type 0 */
371 /* check type of constantpool entry */
372 if (c->cptags[pos] != ctype) {
373 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
377 return c->cpinfos[pos];
381 /* class_free ******************************************************************
383 Frees all resources used by the class.
385 *******************************************************************************/
387 void class_free(classinfo *c)
395 MFREE(c->interfaces, classinfo*, c->interfacescount);
398 for (i = 0; i < c->fieldscount; i++)
399 field_free(&(c->fields[i]));
400 /* MFREE(c->fields, fieldinfo, c->fieldscount); */
404 for (i = 0; i < c->methodscount; i++)
405 method_free(&(c->methods[i]));
406 MFREE(c->methods, methodinfo, c->methodscount);
409 if ((v = c->vftbl) != NULL) {
411 mem_free(v->arraydesc,sizeof(arraydescriptor));
413 for (i = 0; i < v->interfacetablelength; i++) {
414 MFREE(v->interfacetable[-i], methodptr, v->interfacevftbllength[i]);
416 MFREE(v->interfacevftbllength, s4, v->interfacetablelength);
418 i = sizeof(vftbl_t) + sizeof(methodptr) * (v->vftbllength - 1) +
419 sizeof(methodptr*) * (v->interfacetablelength -
420 (v->interfacetablelength > 0));
421 v = (vftbl_t*) (((methodptr*) v) -
422 (v->interfacetablelength - 1) * (v->interfacetablelength > 1));
427 MFREE(c->innerclass, innerclassinfo, c->innerclasscount);
429 /* if (c->classvftbl)
430 mem_free(c->header.vftbl, sizeof(vftbl) + sizeof(methodptr)*(c->vftbl->vftbllength-1)); */
436 /* get_array_class *************************************************************
438 Returns the array class with the given name for the given
439 classloader, or NULL if an exception occurred.
441 Note: This function does eager loading.
443 *******************************************************************************/
445 static classinfo *get_array_class(utf *name,java_objectheader *initloader,
446 java_objectheader *defloader,bool link)
450 /* lookup this class in the classcache */
451 c = classcache_lookup(initloader,name);
453 c = classcache_lookup_defined(defloader,name);
456 /* we have to create it */
457 c = class_create_classinfo(name);
458 c = load_newly_created_array(c,initloader);
464 CLASS_ASSERT(c->state & CLASS_LOADED);
465 CLASS_ASSERT(c->classloader == defloader);
467 if (link && !(c->state & CLASS_LINKED))
471 CLASS_ASSERT(!link || (c->state & CLASS_LINKED));
477 /* class_array_of **************************************************************
479 Returns an array class with the given component class. The array
480 class is dynamically created if neccessary.
482 *******************************************************************************/
484 classinfo *class_array_of(classinfo *component, bool link)
489 /* Assemble the array class name */
490 namelen = component->name->blength;
492 if (component->name->text[0] == '[') {
493 /* the component is itself an array */
494 namebuf = DMNEW(char, namelen + 1);
496 MCOPY(namebuf + 1, component->name->text, char, namelen);
500 /* the component is a non-array class */
501 namebuf = DMNEW(char, namelen + 3);
504 MCOPY(namebuf + 2, component->name->text, char, namelen);
505 namebuf[2 + namelen] = ';';
509 return get_array_class(utf_new(namebuf, namelen),
510 component->classloader,
511 component->classloader,
516 /* class_multiarray_of *********************************************************
518 Returns an array class with the given dimension and element class.
519 The array class is dynamically created if neccessary.
521 *******************************************************************************/
523 classinfo *class_multiarray_of(s4 dim, classinfo *element, bool link)
529 log_text("Invalid array dimension requested");
533 /* Assemble the array class name */
534 namelen = element->name->blength;
536 if (element->name->text[0] == '[') {
537 /* the element is itself an array */
538 namebuf = DMNEW(char, namelen + dim);
539 memcpy(namebuf + dim, element->name->text, namelen);
543 /* the element is a non-array class */
544 namebuf = DMNEW(char, namelen + 2 + dim);
546 memcpy(namebuf + dim + 1, element->name->text, namelen);
547 namelen += (2 + dim);
548 namebuf[namelen - 1] = ';';
550 memset(namebuf, '[', dim);
552 return get_array_class(utf_new(namebuf, namelen),
553 element->classloader,
554 element->classloader,
559 /* class_lookup_classref *******************************************************
561 Looks up the constant_classref for a given classname in the classref
565 cls..............the class containing the reference
566 name.............the name of the class refered to
569 a pointer to a constant_classref, or
570 NULL if the reference was not found
572 *******************************************************************************/
574 constant_classref *class_lookup_classref(classinfo *cls, utf *name)
576 constant_classref *ref;
577 extra_classref *xref;
582 CLASS_ASSERT(!cls->classrefcount || cls->classrefs);
584 /* first search the main classref table */
585 count = cls->classrefcount;
586 ref = cls->classrefs;
587 for (; count; --count, ++ref)
588 if (ref->name == name)
591 /* next try the list of extra classrefs */
592 for (xref = cls->extclassrefs; xref; xref = xref->next) {
593 if (xref->classref.name == name)
594 return &(xref->classref);
602 /* class_get_classref **********************************************************
604 Returns the constant_classref for a given classname.
607 cls..............the class containing the reference
608 name.............the name of the class refered to
611 a pointer to a constant_classref (never NULL)
614 The given name is not checked for validity!
616 *******************************************************************************/
618 constant_classref *class_get_classref(classinfo *cls, utf *name)
620 constant_classref *ref;
621 extra_classref *xref;
626 ref = class_lookup_classref(cls,name);
630 xref = NEW(extra_classref);
631 CLASSREF_INIT(xref->classref,cls,name);
633 xref->next = cls->extclassrefs;
634 cls->extclassrefs = xref;
636 return &(xref->classref);
640 /* class_get_self_classref *****************************************************
642 Returns the constant_classref to the class itself.
645 cls..............the class containing the reference
648 a pointer to a constant_classref (never NULL)
650 *******************************************************************************/
652 constant_classref *class_get_self_classref(classinfo *cls)
654 /* XXX this should be done in a faster way. Maybe always make */
655 /* the classref of index 0 a self reference. */
656 return class_get_classref(cls,cls->name);
659 /* class_get_classref_multiarray_of ********************************************
661 Returns an array type reference with the given dimension and element class
665 dim..............the requested dimension
666 dim must be in [1;255]. This is NOT checked!
667 ref..............the component class reference
670 a pointer to the class reference for the array type
673 The referer of `ref` is used as the referer for the new classref.
675 *******************************************************************************/
677 constant_classref *class_get_classref_multiarray_of(s4 dim, constant_classref *ref)
683 CLASS_ASSERT(dim >= 1 && dim <= 255);
685 /* Assemble the array class name */
686 namelen = ref->name->blength;
688 if (ref->name->text[0] == '[') {
689 /* the element is itself an array */
690 namebuf = DMNEW(char, namelen + dim);
691 memcpy(namebuf + dim, ref->name->text, namelen);
695 /* the element is a non-array class */
696 namebuf = DMNEW(char, namelen + 2 + dim);
698 memcpy(namebuf + dim + 1, ref->name->text, namelen);
699 namelen += (2 + dim);
700 namebuf[namelen - 1] = ';';
702 memset(namebuf, '[', dim);
704 return class_get_classref(ref->referer,utf_new(namebuf, namelen));
708 /* class_get_classref_component_of *********************************************
710 Returns the component classref of a given array type reference
713 ref..............the array type reference
716 a reference to the component class, or
717 NULL if `ref` is not an object array type reference
720 The referer of `ref` is used as the referer for the new classref.
722 *******************************************************************************/
724 constant_classref *class_get_classref_component_of(constant_classref *ref)
731 name = ref->name->text;
735 namelen = ref->name->blength - 1;
740 else if (*name != '[') {
744 return class_get_classref(ref->referer, utf_new(name, namelen));
748 /* class_findmethod ************************************************************
750 Searches a 'classinfo' structure for a method having the given name
751 and descriptor. If descriptor is NULL, it is ignored.
753 *******************************************************************************/
755 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc)
760 for (i = 0; i < c->methodscount; i++) {
761 m = &(c->methods[i]);
763 if ((m->name == name) && ((desc == NULL) || (m->descriptor == desc)))
771 /* class_resolvemethod *********************************************************
773 Searches a class and it's super classes for a method.
775 Superinterfaces are *not* searched.
777 *******************************************************************************/
779 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *desc)
784 m = class_findmethod(c, name, desc);
789 /* JVM Specification bug:
791 It is important NOT to resolve special <init> and <clinit>
792 methods to super classes or interfaces; yet, this is not
793 explicited in the specification. Section 5.4.3.3 should be
794 updated appropriately. */
796 if (name == utf_init || name == utf_clinit)
806 /* class_resolveinterfacemethod_intern *****************************************
808 Internally used helper function. Do not use this directly.
810 *******************************************************************************/
812 static methodinfo *class_resolveinterfacemethod_intern(classinfo *c,
813 utf *name, utf *desc)
818 /* try to find the method in the class */
820 m = class_findmethod(c, name, desc);
825 /* no method found? try the superinterfaces */
827 for (i = 0; i < c->interfacescount; i++) {
828 m = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
835 /* no method found */
841 /* class_resolveclassmethod ****************************************************
843 Resolves a reference from REFERER to a method with NAME and DESC in
846 If the method cannot be resolved the return value is NULL. If
847 EXCEPT is true *exceptionptr is set, too.
849 *******************************************************************************/
851 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *desc,
852 classinfo *referer, bool throwexception)
858 /* if (c->flags & ACC_INTERFACE) { */
859 /* if (throwexception) */
860 /* *exceptionptr = */
861 /* new_exception(string_java_lang_IncompatibleClassChangeError); */
865 /* try class c and its superclasses */
869 m = class_resolvemethod(cls, name, desc);
874 /* try the superinterfaces */
876 for (i = 0; i < c->interfacescount; i++) {
877 m = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
885 exceptions_throw_nosuchmethoderror(c, name, desc);
890 if ((m->flags & ACC_ABSTRACT) && !(c->flags & ACC_ABSTRACT)) {
892 exceptions_throw_abstractmethoderror();
897 /* XXX check access rights */
903 /* class_resolveinterfacemethod ************************************************
905 Resolves a reference from REFERER to a method with NAME and DESC in
908 If the method cannot be resolved the return value is NULL. If
909 EXCEPT is true *exceptionptr is set, too.
911 *******************************************************************************/
913 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *desc,
914 classinfo *referer, bool throwexception)
918 if (!(c->flags & ACC_INTERFACE)) {
921 new_exception(string_java_lang_IncompatibleClassChangeError);
926 mi = class_resolveinterfacemethod_intern(c, name, desc);
931 /* try class java.lang.Object */
933 mi = class_findmethod(class_java_lang_Object, name, desc);
940 exceptions_new_nosuchmethoderror(c, name, desc);
946 /* class_findfield *************************************************************
948 Searches for field with specified name and type in a classinfo
949 structure. If no such field is found NULL is returned.
951 *******************************************************************************/
953 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc)
957 for (i = 0; i < c->fieldscount; i++)
958 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc))
959 return &(c->fields[i]);
962 return class_findfield(c->super.cls, name, desc);
968 /* class_findfield_approx ******************************************************
970 Searches in 'classinfo'-structure for a field with the specified
973 *******************************************************************************/
975 fieldinfo *class_findfield_by_name(classinfo *c, utf *name)
979 /* get field index */
981 i = class_findfield_index_by_name(c, name);
983 /* field was not found, return */
988 /* return field address */
990 return &(c->fields[i]);
994 s4 class_findfield_index_by_name(classinfo *c, utf *name)
998 for (i = 0; i < c->fieldscount; i++) {
999 /* compare field names */
1001 if ((c->fields[i].name == name))
1005 /* field was not found, raise exception */
1007 *exceptionptr = new_exception(string_java_lang_NoSuchFieldException);
1013 /****************** Function: class_resolvefield_int ***************************
1015 This is an internally used helper function. Do not use this directly.
1017 Tries to resolve a field having the given name and type.
1018 If the field cannot be resolved, NULL is returned.
1020 *******************************************************************************/
1022 static fieldinfo *class_resolvefield_int(classinfo *c, utf *name, utf *desc)
1027 /* search for field in class c */
1029 for (i = 0; i < c->fieldscount; i++) {
1030 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc)) {
1031 return &(c->fields[i]);
1035 /* try superinterfaces recursively */
1037 for (i = 0; i < c->interfacescount; i++) {
1038 fi = class_resolvefield_int(c->interfaces[i].cls, name, desc);
1043 /* try superclass */
1046 return class_resolvefield_int(c->super.cls, name, desc);
1054 /********************* Function: class_resolvefield ***************************
1056 Resolves a reference from REFERER to a field with NAME and DESC in class C.
1058 If the field cannot be resolved the return value is NULL. If EXCEPT is
1059 true *exceptionptr is set, too.
1061 *******************************************************************************/
1063 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc,
1064 classinfo *referer, bool throwexception)
1068 fi = class_resolvefield_int(c, name, desc);
1073 new_exception_utfmessage(string_java_lang_NoSuchFieldError,
1079 /* XXX check access rights */
1085 /* class_issubclass ************************************************************
1087 Checks if sub is a descendant of super.
1089 *******************************************************************************/
1091 bool class_issubclass(classinfo *sub, classinfo *super)
1100 sub = sub->super.cls;
1105 /* class_printflags ************************************************************
1107 Prints flags of a class.
1109 *******************************************************************************/
1111 #if !defined(NDEBUG)
1112 void class_printflags(classinfo *c)
1119 if (c->flags & ACC_PUBLIC) printf(" PUBLIC");
1120 if (c->flags & ACC_PRIVATE) printf(" PRIVATE");
1121 if (c->flags & ACC_PROTECTED) printf(" PROTECTED");
1122 if (c->flags & ACC_STATIC) printf(" STATIC");
1123 if (c->flags & ACC_FINAL) printf(" FINAL");
1124 if (c->flags & ACC_SYNCHRONIZED) printf(" SYNCHRONIZED");
1125 if (c->flags & ACC_VOLATILE) printf(" VOLATILE");
1126 if (c->flags & ACC_TRANSIENT) printf(" TRANSIENT");
1127 if (c->flags & ACC_NATIVE) printf(" NATIVE");
1128 if (c->flags & ACC_INTERFACE) printf(" INTERFACE");
1129 if (c->flags & ACC_ABSTRACT) printf(" ABSTRACT");
1134 /* class_print *****************************************************************
1136 Prints classname plus flags.
1138 *******************************************************************************/
1140 #if !defined(NDEBUG)
1141 void class_print(classinfo *c)
1148 utf_display_printable_ascii(c->name);
1149 class_printflags(c);
1154 /* class_classref_print ********************************************************
1156 Prints classname plus referer class.
1158 *******************************************************************************/
1160 #if !defined(NDEBUG)
1161 void class_classref_print(constant_classref *cr)
1168 utf_display_printable_ascii(cr->name);
1171 class_print(cr->referer);
1179 /* class_println ***************************************************************
1181 Prints classname plus flags and new line.
1183 *******************************************************************************/
1185 #if !defined(NDEBUG)
1186 void class_println(classinfo *c)
1194 /* class_classref_println ******************************************************
1196 Prints classname plus referer class and new line.
1198 *******************************************************************************/
1200 #if !defined(NDEBUG)
1201 void class_classref_println(constant_classref *cr)
1203 class_classref_print(cr);
1209 /* class_showconstantpool ******************************************************
1211 Dump the constant pool of the given class to stdout.
1213 *******************************************************************************/
1215 #if !defined(NDEBUG)
1216 void class_showconstantpool (classinfo *c)
1221 printf ("---- dump of constant pool ----\n");
1223 for (i=0; i<c->cpcount; i++) {
1224 printf ("#%d: ", (int) i);
1226 e = c -> cpinfos [i];
1229 switch (c -> cptags [i]) {
1230 case CONSTANT_Class:
1231 printf ("Classreference -> ");
1232 utf_display_printable_ascii ( ((constant_classref*)e) -> name );
1234 case CONSTANT_Fieldref:
1235 printf ("Fieldref -> ");
1236 field_fieldref_print((constant_FMIref *) e);
1238 case CONSTANT_Methodref:
1239 printf ("Methodref -> ");
1240 method_methodref_print((constant_FMIref *) e);
1242 case CONSTANT_InterfaceMethodref:
1243 printf ("InterfaceMethod -> ");
1244 method_methodref_print((constant_FMIref *) e);
1246 case CONSTANT_String:
1247 printf ("String -> ");
1248 utf_display_printable_ascii (e);
1250 case CONSTANT_Integer:
1251 printf ("Integer -> %d", (int) ( ((constant_integer*)e) -> value) );
1253 case CONSTANT_Float:
1254 printf ("Float -> %f", ((constant_float*)e) -> value);
1256 case CONSTANT_Double:
1257 printf ("Double -> %f", ((constant_double*)e) -> value);
1261 u8 v = ((constant_long*)e) -> value;
1263 printf ("Long -> %ld", (long int) v);
1265 printf ("Long -> HI: %ld, LO: %ld\n",
1266 (long int) v.high, (long int) v.low);
1270 case CONSTANT_NameAndType:
1272 constant_nameandtype *cnt = e;
1273 printf ("NameAndType: ");
1274 utf_display_printable_ascii (cnt->name);
1276 utf_display_printable_ascii (cnt->descriptor);
1280 printf ("Utf8 -> ");
1281 utf_display_printable_ascii (e);
1284 log_text("Invalid type of ConstantPool-Entry");
1292 #endif /* !defined(NDEBUG) */
1295 /* class_showmethods ***********************************************************
1297 Dump info about the fields and methods of the given class to stdout.
1299 *******************************************************************************/
1301 #if !defined(NDEBUG)
1302 void class_showmethods (classinfo *c)
1306 printf("--------- Fields and Methods ----------------\n");
1308 class_printflags(c);
1312 utf_display_printable_ascii(c->name);
1317 utf_display_printable_ascii(c->super.cls->name);
1321 printf("Index: %d\n", c->index);
1323 printf("Interfaces:\n");
1324 for (i = 0; i < c->interfacescount; i++) {
1326 utf_display_printable_ascii(c->interfaces[i].cls->name);
1327 printf (" (%d)\n", c->interfaces[i].cls->index);
1330 printf("Fields:\n");
1331 for (i = 0; i < c->fieldscount; i++)
1332 field_println(&(c->fields[i]));
1334 printf("Methods:\n");
1335 for (i = 0; i < c->methodscount; i++) {
1336 methodinfo *m = &(c->methods[i]);
1338 if (!(m->flags & ACC_STATIC))
1339 printf("vftblindex: %d ", m->vftblindex);
1344 printf ("Virtual function table:\n");
1345 for (i = 0; i < c->vftbl->vftbllength; i++)
1346 printf ("entry: %d, %ld\n", i, (long int) (c->vftbl->table[i]));
1348 #endif /* !defined(NDEBUG) */
1352 * These are local overrides for various environment variables in Emacs.
1353 * Please do not remove this and leave it at the end of the file, where
1354 * Emacs will automagically detect them.
1355 * ---------------------------------------------------------------------
1358 * indent-tabs-mode: t
1362 * vim:noexpandtab:sw=4:ts=4: