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 4957 2006-05-26 11:48:10Z edwin $
47 #include "mm/memory.h"
49 #if defined(ENABLE_THREADS)
50 # include "threads/native/threads.h"
53 #include "toolbox/logging.h"
55 #include "vm/classcache.h"
56 #include "vm/exceptions.h"
57 #include "vm/global.h"
58 #include "vm/loader.h"
59 #include "vm/options.h"
60 #include "vm/resolve.h"
61 #include "vm/statistics.h"
62 #include "vm/stringlocal.h"
66 /******************************************************************************/
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_NoClassDefFoundError;
110 classinfo *class_java_lang_LinkageError;
111 classinfo *class_java_lang_NoSuchMethodError;
112 classinfo *class_java_lang_OutOfMemoryError;
114 classinfo *class_java_lang_Exception;
115 classinfo *class_java_lang_ClassNotFoundException;
116 classinfo *class_java_lang_IllegalArgumentException;
117 classinfo *class_java_lang_IllegalMonitorStateException;
119 classinfo *class_java_lang_Void;
120 classinfo *class_java_lang_Boolean;
121 classinfo *class_java_lang_Byte;
122 classinfo *class_java_lang_Character;
123 classinfo *class_java_lang_Short;
124 classinfo *class_java_lang_Integer;
125 classinfo *class_java_lang_Long;
126 classinfo *class_java_lang_Float;
127 classinfo *class_java_lang_Double;
130 /* some runtime exception */
132 classinfo *class_java_lang_NullPointerException;
135 /* some classes which may be used more often */
137 classinfo *class_java_lang_StackTraceElement;
138 classinfo *class_java_lang_reflect_Constructor;
139 classinfo *class_java_lang_reflect_Field;
140 classinfo *class_java_lang_reflect_Method;
141 classinfo *class_java_security_PrivilegedAction;
142 classinfo *class_java_util_Vector;
144 classinfo *arrayclass_java_lang_Object;
147 /* pseudo classes for the typechecker */
149 classinfo *pseudo_class_Arraystub;
150 classinfo *pseudo_class_Null;
151 classinfo *pseudo_class_New;
154 /* class_set_packagename *******************************************************
156 Derive the package name from the class name and store it in the struct.
158 *******************************************************************************/
160 void class_set_packagename(classinfo *c)
162 char *p = UTF_END(c->name) - 1;
163 char *start = c->name->text;
165 /* set the package name */
166 /* classes in the unnamed package keep packagename == NULL */
168 if (c->name->text[0] == '[') {
169 /* set packagename of arrays to the element's package */
171 for (; *start == '['; start++);
173 /* skip the 'L' in arrays of references */
177 for (; (p > start) && (*p != '/'); --p);
179 c->packagename = utf_new(start, p - start);
182 for (; (p > start) && (*p != '/'); --p);
184 c->packagename = utf_new(start, p - start);
189 /* class_create_classinfo ******************************************************
191 Create a new classinfo struct. The class name is set to the given utf *,
192 most other fields are initialized to zero.
194 Note: classname may be NULL. In this case a not-yet-named classinfo is
195 created. The name must be filled in later and class_set_packagename
196 must be called after that.
198 *******************************************************************************/
200 classinfo *class_create_classinfo(utf *classname)
204 #if defined(ENABLE_STATISTICS)
206 count_class_infos += sizeof(classinfo);
209 /* we use a safe name for temporarily unnamed classes */
211 classname = utf_not_named_yet;
215 log_message_utf("Creating class: ", classname);
218 /* GCNEW_UNCOLLECTABLE clears the allocated memory */
220 c = GCNEW_UNCOLLECTABLE(classinfo, 1);
221 /*c=NEW(classinfo);*/
224 /* set the header.vftbl of all loaded classes to the one of
225 java.lang.Class, so Java code can use a class as object */
227 if (class_java_lang_Class)
228 if (class_java_lang_Class->vftbl)
229 c->object.header.vftbl = class_java_lang_Class->vftbl;
231 if (classname != utf_not_named_yet)
232 class_set_packagename(c);
234 #if defined(ENABLE_THREADS)
235 lock_init_object_lock(&c->object.header);
242 /* class_postset_header_vftbl **************************************************
244 Set the header.vftbl of all classes created before java.lang.Class
245 was linked. This is necessary that Java code can use a class as
248 *******************************************************************************/
250 void class_postset_header_vftbl(void)
254 classcache_name_entry *nmen;
255 classcache_class_entry *clsen;
257 assert(class_java_lang_Class);
259 for (slot = 0; slot < hashtable_classcache.size; slot++) {
260 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
262 for (; nmen; nmen = nmen->hashlink) {
263 /* iterate over all class entries */
265 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
268 /* now set the the vftbl */
270 if (c->object.header.vftbl == NULL)
271 c->object.header.vftbl = class_java_lang_Class->vftbl;
278 /* class_freepool **************************************************************
280 Frees all resources used by this classes Constant Pool.
282 *******************************************************************************/
284 static void class_freecpool(classinfo *c)
290 if (c->cptags && c->cpinfos) {
291 for (idx = 0; idx < c->cpcount; idx++) {
292 tag = c->cptags[idx];
293 info = c->cpinfos[idx];
297 case CONSTANT_Fieldref:
298 case CONSTANT_Methodref:
299 case CONSTANT_InterfaceMethodref:
300 FREE(info, constant_FMIref);
302 case CONSTANT_Integer:
303 FREE(info, constant_integer);
306 FREE(info, constant_float);
309 FREE(info, constant_long);
311 case CONSTANT_Double:
312 FREE(info, constant_double);
314 case CONSTANT_NameAndType:
315 FREE(info, constant_nameandtype);
323 MFREE(c->cptags, u1, c->cpcount);
326 MFREE(c->cpinfos, voidptr, c->cpcount);
330 /* class_getconstant ***********************************************************
332 Retrieves the value at position 'pos' of the constantpool of a
333 class. If the type of the value is other than 'ctype', an error is
336 *******************************************************************************/
338 voidptr class_getconstant(classinfo *c, u4 pos, u4 ctype)
340 /* check index and type of constantpool entry */
341 /* (pos == 0 is caught by type comparison) */
343 if (pos >= c->cpcount || c->cptags[pos] != ctype) {
344 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
348 return c->cpinfos[pos];
352 /* innerclass_getconstant ******************************************************
354 Like class_getconstant, but if cptags is ZERO, null is returned.
356 *******************************************************************************/
358 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype)
360 /* invalid position in constantpool */
361 if (pos >= c->cpcount) {
362 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
366 /* constantpool entry of type 0 */
370 /* check type of constantpool entry */
371 if (c->cptags[pos] != ctype) {
372 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
376 return c->cpinfos[pos];
380 /* class_free ******************************************************************
382 Frees all resources used by the class.
384 *******************************************************************************/
386 void class_free(classinfo *c)
394 MFREE(c->interfaces, classinfo*, c->interfacescount);
397 for (i = 0; i < c->fieldscount; i++)
398 field_free(&(c->fields[i]));
399 /* MFREE(c->fields, fieldinfo, c->fieldscount); */
403 for (i = 0; i < c->methodscount; i++)
404 method_free(&(c->methods[i]));
405 MFREE(c->methods, methodinfo, c->methodscount);
408 if ((v = c->vftbl) != NULL) {
410 mem_free(v->arraydesc,sizeof(arraydescriptor));
412 for (i = 0; i < v->interfacetablelength; i++) {
413 MFREE(v->interfacetable[-i], methodptr, v->interfacevftbllength[i]);
415 MFREE(v->interfacevftbllength, s4, v->interfacetablelength);
417 i = sizeof(vftbl_t) + sizeof(methodptr) * (v->vftbllength - 1) +
418 sizeof(methodptr*) * (v->interfacetablelength -
419 (v->interfacetablelength > 0));
420 v = (vftbl_t*) (((methodptr*) v) -
421 (v->interfacetablelength - 1) * (v->interfacetablelength > 1));
426 MFREE(c->innerclass, innerclassinfo, c->innerclasscount);
428 /* if (c->classvftbl)
429 mem_free(c->header.vftbl, sizeof(vftbl) + sizeof(methodptr)*(c->vftbl->vftbllength-1)); */
435 /* get_array_class *************************************************************
437 Returns the array class with the given name for the given
438 classloader, or NULL if an exception occurred.
440 Note: This function does eager loading.
442 *******************************************************************************/
444 static classinfo *get_array_class(utf *name,java_objectheader *initloader,
445 java_objectheader *defloader,bool link)
449 /* lookup this class in the classcache */
450 c = classcache_lookup(initloader,name);
452 c = classcache_lookup_defined(defloader,name);
455 /* we have to create it */
456 c = class_create_classinfo(name);
457 c = load_newly_created_array(c,initloader);
463 CLASS_ASSERT(c->state & CLASS_LOADED);
464 CLASS_ASSERT(c->classloader == defloader);
466 if (link && !(c->state & CLASS_LINKED))
470 CLASS_ASSERT(!link || (c->state & CLASS_LINKED));
476 /* class_array_of **************************************************************
478 Returns an array class with the given component class. The array
479 class is dynamically created if neccessary.
481 *******************************************************************************/
483 classinfo *class_array_of(classinfo *component, bool link)
488 /* Assemble the array class name */
489 namelen = component->name->blength;
491 if (component->name->text[0] == '[') {
492 /* the component is itself an array */
493 namebuf = DMNEW(char, namelen + 1);
495 MCOPY(namebuf + 1, component->name->text, char, namelen);
499 /* the component is a non-array class */
500 namebuf = DMNEW(char, namelen + 3);
503 MCOPY(namebuf + 2, component->name->text, char, namelen);
504 namebuf[2 + namelen] = ';';
508 return get_array_class(utf_new(namebuf, namelen),
509 component->classloader,
510 component->classloader,
515 /* class_multiarray_of *********************************************************
517 Returns an array class with the given dimension and element class.
518 The array class is dynamically created if neccessary.
520 *******************************************************************************/
522 classinfo *class_multiarray_of(s4 dim, classinfo *element, bool link)
528 log_text("Invalid array dimension requested");
532 /* Assemble the array class name */
533 namelen = element->name->blength;
535 if (element->name->text[0] == '[') {
536 /* the element is itself an array */
537 namebuf = DMNEW(char, namelen + dim);
538 memcpy(namebuf + dim, element->name->text, namelen);
542 /* the element is a non-array class */
543 namebuf = DMNEW(char, namelen + 2 + dim);
545 memcpy(namebuf + dim + 1, element->name->text, namelen);
546 namelen += (2 + dim);
547 namebuf[namelen - 1] = ';';
549 memset(namebuf, '[', dim);
551 return get_array_class(utf_new(namebuf, namelen),
552 element->classloader,
553 element->classloader,
558 /* class_lookup_classref *******************************************************
560 Looks up the constant_classref for a given classname in the classref
564 cls..............the class containing the reference
565 name.............the name of the class refered to
568 a pointer to a constant_classref, or
569 NULL if the reference was not found
571 *******************************************************************************/
573 constant_classref *class_lookup_classref(classinfo *cls, utf *name)
575 constant_classref *ref;
576 extra_classref *xref;
581 CLASS_ASSERT(!cls->classrefcount || cls->classrefs);
583 /* first search the main classref table */
584 count = cls->classrefcount;
585 ref = cls->classrefs;
586 for (; count; --count, ++ref)
587 if (ref->name == name)
590 /* next try the list of extra classrefs */
591 for (xref = cls->extclassrefs; xref; xref = xref->next) {
592 if (xref->classref.name == name)
593 return &(xref->classref);
601 /* class_get_classref **********************************************************
603 Returns the constant_classref for a given classname.
606 cls..............the class containing the reference
607 name.............the name of the class refered to
610 a pointer to a constant_classref (never NULL)
613 The given name is not checked for validity!
615 *******************************************************************************/
617 constant_classref *class_get_classref(classinfo *cls, utf *name)
619 constant_classref *ref;
620 extra_classref *xref;
625 ref = class_lookup_classref(cls,name);
629 xref = NEW(extra_classref);
630 CLASSREF_INIT(xref->classref,cls,name);
632 xref->next = cls->extclassrefs;
633 cls->extclassrefs = xref;
635 return &(xref->classref);
639 /* class_get_self_classref *****************************************************
641 Returns the constant_classref to the class itself.
644 cls..............the class containing the reference
647 a pointer to a constant_classref (never NULL)
649 *******************************************************************************/
651 constant_classref *class_get_self_classref(classinfo *cls)
653 /* XXX this should be done in a faster way. Maybe always make */
654 /* the classref of index 0 a self reference. */
655 return class_get_classref(cls,cls->name);
658 /* class_get_classref_multiarray_of ********************************************
660 Returns an array type reference with the given dimension and element class
664 dim..............the requested dimension
665 dim must be in [1;255]. This is NOT checked!
666 ref..............the component class reference
669 a pointer to the class reference for the array type
672 The referer of `ref` is used as the referer for the new classref.
674 *******************************************************************************/
676 constant_classref *class_get_classref_multiarray_of(s4 dim, constant_classref *ref)
682 CLASS_ASSERT(dim >= 1 && dim <= 255);
684 /* Assemble the array class name */
685 namelen = ref->name->blength;
687 if (ref->name->text[0] == '[') {
688 /* the element is itself an array */
689 namebuf = DMNEW(char, namelen + dim);
690 memcpy(namebuf + dim, ref->name->text, namelen);
694 /* the element is a non-array class */
695 namebuf = DMNEW(char, namelen + 2 + dim);
697 memcpy(namebuf + dim + 1, ref->name->text, namelen);
698 namelen += (2 + dim);
699 namebuf[namelen - 1] = ';';
701 memset(namebuf, '[', dim);
703 return class_get_classref(ref->referer,utf_new(namebuf, namelen));
707 /* class_get_classref_component_of *********************************************
709 Returns the component classref of a given array type reference
712 ref..............the array type reference
715 a reference to the component class, or
716 NULL if `ref` is not an object array type reference
719 The referer of `ref` is used as the referer for the new classref.
721 *******************************************************************************/
723 constant_classref *class_get_classref_component_of(constant_classref *ref)
730 name = ref->name->text;
734 namelen = ref->name->blength - 1;
739 else if (*name != '[') {
743 return class_get_classref(ref->referer, utf_new(name, namelen));
747 /* class_findmethod ************************************************************
749 Searches a 'classinfo' structure for a method having the given name
750 and descriptor. If descriptor is NULL, it is ignored.
752 *******************************************************************************/
754 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc)
759 for (i = 0; i < c->methodscount; i++) {
760 m = &(c->methods[i]);
762 if ((m->name == name) && ((desc == NULL) || (m->descriptor == desc)))
770 /* class_resolvemethod *********************************************************
772 Searches a class and it's super classes for a method.
774 Superinterfaces are *not* searched.
776 *******************************************************************************/
778 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *desc)
783 m = class_findmethod(c, name, desc);
788 /* JVM Specification bug:
790 It is important NOT to resolve special <init> and <clinit>
791 methods to super classes or interfaces; yet, this is not
792 explicited in the specification. Section 5.4.3.3 should be
793 updated appropriately. */
795 if (name == utf_init || name == utf_clinit)
805 /* class_resolveinterfacemethod_intern *****************************************
807 Internally used helper function. Do not use this directly.
809 *******************************************************************************/
811 static methodinfo *class_resolveinterfacemethod_intern(classinfo *c,
812 utf *name, utf *desc)
817 m = class_findmethod(c, name, desc);
822 /* try the superinterfaces */
824 for (i = 0; i < c->interfacescount; i++) {
825 m = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
836 /* class_resolveclassmethod ****************************************************
838 Resolves a reference from REFERER to a method with NAME and DESC in
841 If the method cannot be resolved the return value is NULL. If
842 EXCEPT is true *exceptionptr is set, too.
844 *******************************************************************************/
846 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *desc,
847 classinfo *referer, bool throwexception)
853 /* if (c->flags & ACC_INTERFACE) { */
854 /* if (throwexception) */
855 /* *exceptionptr = */
856 /* new_exception(string_java_lang_IncompatibleClassChangeError); */
860 /* try class c and its superclasses */
864 m = class_resolvemethod(cls, name, desc);
869 /* try the superinterfaces */
871 for (i = 0; i < c->interfacescount; i++) {
872 m = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
880 *exceptionptr = exceptions_new_nosuchmethoderror(c, name, desc);
885 if ((m->flags & ACC_ABSTRACT) && !(c->flags & ACC_ABSTRACT)) {
887 *exceptionptr = new_exception(string_java_lang_AbstractMethodError);
892 /* XXX check access rights */
898 /* class_resolveinterfacemethod ************************************************
900 Resolves a reference from REFERER to a method with NAME and DESC in
903 If the method cannot be resolved the return value is NULL. If
904 EXCEPT is true *exceptionptr is set, too.
906 *******************************************************************************/
908 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *desc,
909 classinfo *referer, bool throwexception)
913 if (!(c->flags & ACC_INTERFACE)) {
916 new_exception(string_java_lang_IncompatibleClassChangeError);
921 mi = class_resolveinterfacemethod_intern(c, name, desc);
926 /* try class java.lang.Object */
928 mi = class_findmethod(class_java_lang_Object, name, desc);
935 exceptions_new_nosuchmethoderror(c, name, desc);
941 /* class_findfield *************************************************************
943 Searches for field with specified name and type in a classinfo
944 structure. If no such field is found NULL is returned.
946 *******************************************************************************/
948 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc)
952 for (i = 0; i < c->fieldscount; i++)
953 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc))
954 return &(c->fields[i]);
957 return class_findfield(c->super.cls, name, desc);
963 /* class_findfield_approx ******************************************************
965 Searches in 'classinfo'-structure for a field with the specified
968 *******************************************************************************/
970 fieldinfo *class_findfield_by_name(classinfo *c, utf *name)
974 /* get field index */
976 i = class_findfield_index_by_name(c, name);
978 /* field was not found, return */
983 /* return field address */
985 return &(c->fields[i]);
989 s4 class_findfield_index_by_name(classinfo *c, utf *name)
993 for (i = 0; i < c->fieldscount; i++) {
994 /* compare field names */
996 if ((c->fields[i].name == name))
1000 /* field was not found, raise exception */
1002 *exceptionptr = new_exception(string_java_lang_NoSuchFieldException);
1008 /****************** Function: class_resolvefield_int ***************************
1010 This is an internally used helper function. Do not use this directly.
1012 Tries to resolve a field having the given name and type.
1013 If the field cannot be resolved, NULL is returned.
1015 *******************************************************************************/
1017 static fieldinfo *class_resolvefield_int(classinfo *c, utf *name, utf *desc)
1022 /* search for field in class c */
1024 for (i = 0; i < c->fieldscount; i++) {
1025 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc)) {
1026 return &(c->fields[i]);
1030 /* try superinterfaces recursively */
1032 for (i = 0; i < c->interfacescount; i++) {
1033 fi = class_resolvefield_int(c->interfaces[i].cls, name, desc);
1038 /* try superclass */
1041 return class_resolvefield_int(c->super.cls, name, desc);
1049 /********************* Function: class_resolvefield ***************************
1051 Resolves a reference from REFERER to a field with NAME and DESC in class C.
1053 If the field cannot be resolved the return value is NULL. If EXCEPT is
1054 true *exceptionptr is set, too.
1056 *******************************************************************************/
1058 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc,
1059 classinfo *referer, bool throwexception)
1063 fi = class_resolvefield_int(c, name, desc);
1068 new_exception_utfmessage(string_java_lang_NoSuchFieldError,
1074 /* XXX check access rights */
1080 /* class_issubclass ************************************************************
1082 Checks if sub is a descendant of super.
1084 *******************************************************************************/
1086 bool class_issubclass(classinfo *sub, classinfo *super)
1095 sub = sub->super.cls;
1100 /* class_printflags ************************************************************
1102 Prints flags of a class.
1104 *******************************************************************************/
1106 #if !defined(NDEBUG)
1107 void class_printflags(classinfo *c)
1114 if (c->flags & ACC_PUBLIC) printf(" PUBLIC");
1115 if (c->flags & ACC_PRIVATE) printf(" PRIVATE");
1116 if (c->flags & ACC_PROTECTED) printf(" PROTECTED");
1117 if (c->flags & ACC_STATIC) printf(" STATIC");
1118 if (c->flags & ACC_FINAL) printf(" FINAL");
1119 if (c->flags & ACC_SYNCHRONIZED) printf(" SYNCHRONIZED");
1120 if (c->flags & ACC_VOLATILE) printf(" VOLATILE");
1121 if (c->flags & ACC_TRANSIENT) printf(" TRANSIENT");
1122 if (c->flags & ACC_NATIVE) printf(" NATIVE");
1123 if (c->flags & ACC_INTERFACE) printf(" INTERFACE");
1124 if (c->flags & ACC_ABSTRACT) printf(" ABSTRACT");
1129 /* class_print *****************************************************************
1131 Prints classname plus flags.
1133 *******************************************************************************/
1135 #if !defined(NDEBUG)
1136 void class_print(classinfo *c)
1143 utf_display_printable_ascii(c->name);
1144 class_printflags(c);
1149 /* class_classref_print ********************************************************
1151 Prints classname plus referer class.
1153 *******************************************************************************/
1155 #if !defined(NDEBUG)
1156 void class_classref_print(constant_classref *cr)
1163 utf_display_printable_ascii(cr->name);
1166 class_print(cr->referer);
1174 /* class_println ***************************************************************
1176 Prints classname plus flags and new line.
1178 *******************************************************************************/
1180 #if !defined(NDEBUG)
1181 void class_println(classinfo *c)
1189 /* class_classref_println ******************************************************
1191 Prints classname plus referer class and new line.
1193 *******************************************************************************/
1195 #if !defined(NDEBUG)
1196 void class_classref_println(constant_classref *cr)
1198 class_classref_print(cr);
1204 /* class_showconstantpool ******************************************************
1206 Dump the constant pool of the given class to stdout.
1208 *******************************************************************************/
1210 #if !defined(NDEBUG)
1211 void class_showconstantpool (classinfo *c)
1216 printf ("---- dump of constant pool ----\n");
1218 for (i=0; i<c->cpcount; i++) {
1219 printf ("#%d: ", (int) i);
1221 e = c -> cpinfos [i];
1224 switch (c -> cptags [i]) {
1225 case CONSTANT_Class:
1226 printf ("Classreference -> ");
1227 utf_display_printable_ascii ( ((constant_classref*)e) -> name );
1229 case CONSTANT_Fieldref:
1230 printf ("Fieldref -> ");
1231 field_fieldref_print((constant_FMIref *) e);
1233 case CONSTANT_Methodref:
1234 printf ("Methodref -> ");
1235 method_methodref_print((constant_FMIref *) e);
1237 case CONSTANT_InterfaceMethodref:
1238 printf ("InterfaceMethod -> ");
1239 method_methodref_print((constant_FMIref *) e);
1241 case CONSTANT_String:
1242 printf ("String -> ");
1243 utf_display_printable_ascii (e);
1245 case CONSTANT_Integer:
1246 printf ("Integer -> %d", (int) ( ((constant_integer*)e) -> value) );
1248 case CONSTANT_Float:
1249 printf ("Float -> %f", ((constant_float*)e) -> value);
1251 case CONSTANT_Double:
1252 printf ("Double -> %f", ((constant_double*)e) -> value);
1256 u8 v = ((constant_long*)e) -> value;
1258 printf ("Long -> %ld", (long int) v);
1260 printf ("Long -> HI: %ld, LO: %ld\n",
1261 (long int) v.high, (long int) v.low);
1265 case CONSTANT_NameAndType:
1267 constant_nameandtype *cnt = e;
1268 printf ("NameAndType: ");
1269 utf_display_printable_ascii (cnt->name);
1271 utf_display_printable_ascii (cnt->descriptor);
1275 printf ("Utf8 -> ");
1276 utf_display_printable_ascii (e);
1279 log_text("Invalid type of ConstantPool-Entry");
1287 #endif /* !defined(NDEBUG) */
1290 /* class_showmethods ***********************************************************
1292 Dump info about the fields and methods of the given class to stdout.
1294 *******************************************************************************/
1296 #if !defined(NDEBUG)
1297 void class_showmethods (classinfo *c)
1301 printf("--------- Fields and Methods ----------------\n");
1303 class_printflags(c);
1307 utf_display_printable_ascii(c->name);
1312 utf_display_printable_ascii(c->super.cls->name);
1316 printf("Index: %d\n", c->index);
1318 printf("Interfaces:\n");
1319 for (i = 0; i < c->interfacescount; i++) {
1321 utf_display_printable_ascii(c->interfaces[i].cls->name);
1322 printf (" (%d)\n", c->interfaces[i].cls->index);
1325 printf("Fields:\n");
1326 for (i = 0; i < c->fieldscount; i++)
1327 field_println(&(c->fields[i]));
1329 printf("Methods:\n");
1330 for (i = 0; i < c->methodscount; i++) {
1331 methodinfo *m = &(c->methods[i]);
1333 if (!(m->flags & ACC_STATIC))
1334 printf("vftblindex: %d ", m->vftblindex);
1339 printf ("Virtual function table:\n");
1340 for (i = 0; i < c->vftbl->vftbllength; i++)
1341 printf ("entry: %d, %ld\n", i, (long int) (c->vftbl->table[i]));
1343 #endif /* !defined(NDEBUG) */
1347 * These are local overrides for various environment variables in Emacs.
1348 * Please do not remove this and leave it at the end of the file, where
1349 * Emacs will automagically detect them.
1350 * ---------------------------------------------------------------------
1353 * indent-tabs-mode: t
1357 * vim:noexpandtab:sw=4:ts=4: