1 /* src/vm/class.c - class related functions
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Reinhard Grafl
33 $Id: class.c 3638 2005-11-08 17:21:11Z twisti $
43 #include "mm/memory.h"
45 #if defined(USE_THREADS)
46 # if defined(NATIVE_THREADS)
47 # include "threads/native/threads.h"
49 # include "threads/green/threads.h"
50 # include "threads/green/locks.h"
54 #include "toolbox/logging.h"
56 #include "vm/classcache.h"
57 #include "vm/exceptions.h"
58 #include "vm/global.h"
59 #include "vm/loader.h"
60 #include "vm/options.h"
61 #include "vm/resolve.h"
62 #include "vm/statistics.h"
63 #include "vm/stringlocal.h"
64 #include "vm/tables.h"
68 /******************************************************************************/
70 /******************************************************************************/
77 #define CLASS_ASSERT(cond) assert(cond)
79 #define CLASS_ASSERT(cond)
83 /* global variables ***********************************************************/
85 list unlinkedclasses; /* this is only used for eager class */
89 /* frequently used classes ****************************************************/
91 /* important system classes */
93 classinfo *class_java_lang_Object = NULL;
94 classinfo *class_java_lang_Class = NULL;
95 classinfo *class_java_lang_ClassLoader = NULL;
96 classinfo *class_java_lang_Cloneable = NULL;
97 classinfo *class_java_lang_SecurityManager = NULL;
98 classinfo *class_java_lang_String = NULL;
99 classinfo *class_java_lang_System = NULL;
100 classinfo *class_java_lang_Thread = NULL;
101 classinfo *class_java_lang_ThreadGroup = NULL;
102 classinfo *class_java_lang_VMThread = NULL;
103 classinfo *class_java_io_Serializable = NULL;
106 /* system exception classes required in cacao */
108 classinfo *class_java_lang_Throwable = NULL;
109 classinfo *class_java_lang_VMThrowable = NULL;
110 classinfo *class_java_lang_Error = NULL;
111 classinfo *class_java_lang_NoClassDefFoundError = NULL;
112 classinfo *class_java_lang_NoSuchMethodError = NULL;
113 classinfo *class_java_lang_OutOfMemoryError = NULL;
115 classinfo *class_java_lang_Exception = NULL;
116 classinfo *class_java_lang_ClassNotFoundException = NULL;
117 classinfo *class_java_lang_IllegalArgumentException = NULL;
118 classinfo *class_java_lang_IllegalMonitorStateException = NULL;
120 classinfo *class_java_lang_Void = NULL;
121 classinfo *class_java_lang_Boolean = NULL;
122 classinfo *class_java_lang_Byte = NULL;
123 classinfo *class_java_lang_Character = NULL;
124 classinfo *class_java_lang_Short = NULL;
125 classinfo *class_java_lang_Integer = NULL;
126 classinfo *class_java_lang_Long = NULL;
127 classinfo *class_java_lang_Float = NULL;
128 classinfo *class_java_lang_Double = NULL;
131 /* some runtime exception */
133 classinfo *class_java_lang_NullPointerException = NULL;
136 /* some classes which may be used more often */
138 classinfo *class_java_lang_StackTraceElement = NULL;
139 classinfo *class_java_lang_reflect_Constructor = NULL;
140 classinfo *class_java_lang_reflect_Field = NULL;
141 classinfo *class_java_lang_reflect_Method = NULL;
142 classinfo *class_java_security_PrivilegedAction = NULL;
143 classinfo *class_java_util_Vector = NULL;
145 classinfo *arrayclass_java_lang_Object = NULL;
148 /* pseudo classes for the typechecker */
150 classinfo *pseudo_class_Arraystub = NULL;
151 classinfo *pseudo_class_Null = NULL;
152 classinfo *pseudo_class_New = NULL;
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(STATISTICS)
207 count_class_infos += sizeof(classinfo);
210 /* we use a safe name for temporarily unnamed classes */
212 classname = utf_not_named_yet;
215 log_message_utf("Creating class: ", classname);
217 /* GCNEW_UNCOLLECTABLE clears the allocated memory */
219 c = GCNEW_UNCOLLECTABLE(classinfo, 1);
220 /*c=NEW(classinfo);*/
223 if (classname != utf_not_named_yet) {
224 class_set_packagename(c);
227 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
228 initObjectLock(&c->header);
234 /* class_freepool **************************************************************
236 Frees all resources used by this classes Constant Pool.
238 *******************************************************************************/
240 static void class_freecpool(classinfo *c)
246 if (c->cptags && c->cpinfos) {
247 for (idx = 0; idx < c->cpcount; idx++) {
248 tag = c->cptags[idx];
249 info = c->cpinfos[idx];
253 case CONSTANT_Fieldref:
254 case CONSTANT_Methodref:
255 case CONSTANT_InterfaceMethodref:
256 FREE(info, constant_FMIref);
258 case CONSTANT_Integer:
259 FREE(info, constant_integer);
262 FREE(info, constant_float);
265 FREE(info, constant_long);
267 case CONSTANT_Double:
268 FREE(info, constant_double);
270 case CONSTANT_NameAndType:
271 FREE(info, constant_nameandtype);
279 MFREE(c->cptags, u1, c->cpcount);
282 MFREE(c->cpinfos, voidptr, c->cpcount);
286 /* class_getconstant ***********************************************************
288 Retrieves the value at position 'pos' of the constantpool of a
289 class. If the type of the value is other than 'ctype', an error is
292 *******************************************************************************/
294 voidptr class_getconstant(classinfo *c, u4 pos, u4 ctype)
296 /* check index and type of constantpool entry */
297 /* (pos == 0 is caught by type comparison) */
299 if (pos >= c->cpcount || c->cptags[pos] != ctype) {
300 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
304 return c->cpinfos[pos];
308 /* innerclass_getconstant ******************************************************
310 Like class_getconstant, but if cptags is ZERO, null is returned.
312 *******************************************************************************/
314 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype)
316 /* invalid position in constantpool */
317 if (pos >= c->cpcount) {
318 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
322 /* constantpool entry of type 0 */
326 /* check type of constantpool entry */
327 if (c->cptags[pos] != ctype) {
328 *exceptionptr = new_classformaterror(c, "Illegal constant pool index");
332 return c->cpinfos[pos];
336 /* class_free ******************************************************************
338 Frees all resources used by the class.
340 *******************************************************************************/
342 void class_free(classinfo *c)
350 MFREE(c->interfaces, classinfo*, c->interfacescount);
353 for (i = 0; i < c->fieldscount; i++)
354 field_free(&(c->fields[i]));
355 /* MFREE(c->fields, fieldinfo, c->fieldscount); */
359 for (i = 0; i < c->methodscount; i++)
360 method_free(&(c->methods[i]));
361 MFREE(c->methods, methodinfo, c->methodscount);
364 if ((v = c->vftbl) != NULL) {
366 mem_free(v->arraydesc,sizeof(arraydescriptor));
368 for (i = 0; i < v->interfacetablelength; i++) {
369 MFREE(v->interfacetable[-i], methodptr, v->interfacevftbllength[i]);
371 MFREE(v->interfacevftbllength, s4, v->interfacetablelength);
373 i = sizeof(vftbl_t) + sizeof(methodptr) * (v->vftbllength - 1) +
374 sizeof(methodptr*) * (v->interfacetablelength -
375 (v->interfacetablelength > 0));
376 v = (vftbl_t*) (((methodptr*) v) -
377 (v->interfacetablelength - 1) * (v->interfacetablelength > 1));
382 MFREE(c->innerclass, innerclassinfo, c->innerclasscount);
384 /* if (c->classvftbl)
385 mem_free(c->header.vftbl, sizeof(vftbl) + sizeof(methodptr)*(c->vftbl->vftbllength-1)); */
391 /* get_array_class *************************************************************
393 Returns the array class with the given name for the given
394 classloader, or NULL if an exception occurred.
396 Note: This function does eager loading.
398 *******************************************************************************/
400 static classinfo *get_array_class(utf *name,java_objectheader *initloader,
401 java_objectheader *defloader,bool link)
405 /* lookup this class in the classcache */
406 c = classcache_lookup(initloader,name);
408 c = classcache_lookup_defined(defloader,name);
411 /* we have to create it */
412 c = class_create_classinfo(name);
413 c = load_newly_created_array(c,initloader);
419 CLASS_ASSERT(c->loaded);
420 CLASS_ASSERT(c->classloader == defloader);
422 if (link && !c->linked)
426 CLASS_ASSERT(!link || c->linked);
432 /* class_array_of **************************************************************
434 Returns an array class with the given component class. The array
435 class is dynamically created if neccessary.
437 *******************************************************************************/
439 classinfo *class_array_of(classinfo *component, bool link)
444 /* Assemble the array class name */
445 namelen = component->name->blength;
447 if (component->name->text[0] == '[') {
448 /* the component is itself an array */
449 namebuf = DMNEW(char, namelen + 1);
451 MCOPY(namebuf + 1, component->name->text, char, namelen);
455 /* the component is a non-array class */
456 namebuf = DMNEW(char, namelen + 3);
459 MCOPY(namebuf + 2, component->name->text, char, namelen);
460 namebuf[2 + namelen] = ';';
464 return get_array_class(utf_new(namebuf, namelen),
465 component->classloader,
466 component->classloader,
471 /* class_multiarray_of *********************************************************
473 Returns an array class with the given dimension and element class.
474 The array class is dynamically created if neccessary.
476 *******************************************************************************/
478 classinfo *class_multiarray_of(s4 dim, classinfo *element, bool link)
484 log_text("Invalid array dimension requested");
488 /* Assemble the array class name */
489 namelen = element->name->blength;
491 if (element->name->text[0] == '[') {
492 /* the element is itself an array */
493 namebuf = DMNEW(char, namelen + dim);
494 memcpy(namebuf + dim, element->name->text, namelen);
498 /* the element is a non-array class */
499 namebuf = DMNEW(char, namelen + 2 + dim);
501 memcpy(namebuf + dim + 1, element->name->text, namelen);
502 namelen += (2 + dim);
503 namebuf[namelen - 1] = ';';
505 memset(namebuf, '[', dim);
507 return get_array_class(utf_new(namebuf, namelen),
508 element->classloader,
509 element->classloader,
514 /* class_lookup_classref *******************************************************
516 Looks up the constant_classref for a given classname in the classref
520 cls..............the class containing the reference
521 name.............the name of the class refered to
524 a pointer to a constant_classref, or
525 NULL if the reference was not found
527 *******************************************************************************/
529 constant_classref *class_lookup_classref(classinfo *cls, utf *name)
531 constant_classref *ref;
532 extra_classref *xref;
537 CLASS_ASSERT(!cls->classrefcount || cls->classrefs);
539 /* first search the main classref table */
540 count = cls->classrefcount;
541 ref = cls->classrefs;
542 for (; count; --count, ++ref)
543 if (ref->name == name)
546 /* next try the list of extra classrefs */
547 for (xref = cls->extclassrefs; xref; xref = xref->next) {
548 if (xref->classref.name == name)
549 return &(xref->classref);
557 /* class_get_classref **********************************************************
559 Returns the constant_classref for a given classname.
562 cls..............the class containing the reference
563 name.............the name of the class refered to
566 a pointer to a constant_classref (never NULL)
569 The given name is not checked for validity!
571 *******************************************************************************/
573 constant_classref *class_get_classref(classinfo *cls, utf *name)
575 constant_classref *ref;
576 extra_classref *xref;
581 ref = class_lookup_classref(cls,name);
585 xref = NEW(extra_classref);
586 CLASSREF_INIT(xref->classref,cls,name);
588 xref->next = cls->extclassrefs;
589 cls->extclassrefs = xref;
591 return &(xref->classref);
595 /* class_get_self_classref *****************************************************
597 Returns the constant_classref to the class itself.
600 cls..............the class containing the reference
603 a pointer to a constant_classref (never NULL)
605 *******************************************************************************/
607 constant_classref *class_get_self_classref(classinfo *cls)
609 /* XXX this should be done in a faster way. Maybe always make */
610 /* the classref of index 0 a self reference. */
611 return class_get_classref(cls,cls->name);
614 /* class_get_classref_multiarray_of ********************************************
616 Returns an array type reference with the given dimension and element class
620 dim..............the requested dimension
621 dim must be in [1;255]. This is NOT checked!
622 ref..............the component class reference
625 a pointer to the class reference for the array type
628 The referer of `ref` is used as the referer for the new classref.
630 *******************************************************************************/
632 constant_classref *class_get_classref_multiarray_of(s4 dim, constant_classref *ref)
638 CLASS_ASSERT(dim >= 1 && dim <= 255);
640 /* Assemble the array class name */
641 namelen = ref->name->blength;
643 if (ref->name->text[0] == '[') {
644 /* the element is itself an array */
645 namebuf = DMNEW(char, namelen + dim);
646 memcpy(namebuf + dim, ref->name->text, namelen);
650 /* the element is a non-array class */
651 namebuf = DMNEW(char, namelen + 2 + dim);
653 memcpy(namebuf + dim + 1, ref->name->text, namelen);
654 namelen += (2 + dim);
655 namebuf[namelen - 1] = ';';
657 memset(namebuf, '[', dim);
659 return class_get_classref(ref->referer,utf_new(namebuf, namelen));
663 /* class_get_classref_component_of *********************************************
665 Returns the component classref of a given array type reference
668 ref..............the array type reference
671 a reference to the component class, or
672 NULL if `ref` is not an object array type reference
675 The referer of `ref` is used as the referer for the new classref.
677 *******************************************************************************/
679 constant_classref *class_get_classref_component_of(constant_classref *ref)
686 name = ref->name->text;
690 namelen = ref->name->blength - 1;
695 else if (*name != '[') {
699 return class_get_classref(ref->referer, utf_new(name, namelen));
703 /* class_findmethod ************************************************************
705 Searches a 'classinfo' structure for a method having the given name
706 and descriptor. If descriptor is NULL, it is ignored.
708 *******************************************************************************/
710 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc)
715 for (i = 0; i < c->methodscount; i++) {
716 m = &(c->methods[i]);
718 if ((m->name == name) && ((desc == NULL) || (m->descriptor == desc)))
726 /************************* Function: class_findmethod_approx ******************
728 like class_findmethod but ignores the return value when comparing the
731 *******************************************************************************/
733 methodinfo *class_findmethod_approx(classinfo *c, utf *name, utf *desc)
737 for (i = 0; i < c->methodscount; i++) {
738 if (c->methods[i].name == name) {
739 utf *meth_descr = c->methods[i].descriptor;
743 return &(c->methods[i]);
745 if (desc->blength <= meth_descr->blength) {
746 /* current position in utf text */
747 char *desc_utf_ptr = desc->text;
748 char *meth_utf_ptr = meth_descr->text;
749 /* points behind utf strings */
750 char *desc_end = UTF_END(desc);
751 char *meth_end = UTF_END(meth_descr);
754 /* compare argument types */
755 while (desc_utf_ptr < desc_end && meth_utf_ptr < meth_end) {
757 if ((ch = *desc_utf_ptr++) != (*meth_utf_ptr++))
758 break; /* no match */
761 return &(c->methods[i]); /* all parameter types equal */
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 m = class_findmethod(c, name, desc);
823 /* try the superinterfaces */
825 for (i = 0; i < c->interfacescount; i++) {
826 m = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
837 /* class_resolveclassmethod ****************************************************
839 Resolves a reference from REFERER to a method with NAME and DESC in
842 If the method cannot be resolved the return value is NULL. If
843 EXCEPT is true *exceptionptr is set, too.
845 *******************************************************************************/
847 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *desc,
848 classinfo *referer, bool except)
854 /* XXX resolve class c */
855 /* XXX check access from REFERER to C */
857 /* if (c->flags & ACC_INTERFACE) { */
859 /* *exceptionptr = */
860 /* new_exception(string_java_lang_IncompatibleClassChangeError); */
864 /* try class c and its superclasses */
868 m = class_resolvemethod(cls, name, desc);
873 /* try the superinterfaces */
875 for (i = 0; i < c->interfacescount; i++) {
876 m = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
884 *exceptionptr = exceptions_new_nosuchmethoderror(c, name, desc);
889 if ((m->flags & ACC_ABSTRACT) && !(c->flags & ACC_ABSTRACT)) {
891 *exceptionptr = new_exception(string_java_lang_AbstractMethodError);
896 /* XXX check access rights */
902 /* class_resolveinterfacemethod ************************************************
904 Resolves a reference from REFERER to a method with NAME and DESC in
907 If the method cannot be resolved the return value is NULL. If
908 EXCEPT is true *exceptionptr is set, too.
910 *******************************************************************************/
912 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *desc,
913 classinfo *referer, bool except)
917 /* XXX resolve class c */
918 /* XXX check access from REFERER to C */
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 except)
1070 /* XXX resolve class c */
1071 /* XXX check access from REFERER to C */
1073 fi = class_resolvefield_int(c, name, desc);
1078 new_exception_utfmessage(string_java_lang_NoSuchFieldError,
1084 /* XXX check access rights */
1090 /* class_issubclass ************************************************************
1092 Checks if sub is a descendant of super.
1094 *******************************************************************************/
1096 bool class_issubclass(classinfo *sub, classinfo *super)
1105 sub = sub->super.cls;
1110 void class_showconstanti(classinfo *c, int ii)
1116 printf ("#%d: ", (int) i);
1118 switch (c->cptags [i]) {
1119 case CONSTANT_Class:
1120 printf("Classreference -> ");
1121 utf_display(((constant_classref*)e)->name);
1124 case CONSTANT_Fieldref:
1125 printf("Fieldref -> "); goto displayFMIi;
1126 case CONSTANT_Methodref:
1127 printf("Methodref -> "); goto displayFMIi;
1128 case CONSTANT_InterfaceMethodref:
1129 printf("InterfaceMethod -> "); goto displayFMIi;
1132 constant_FMIref *fmi = e;
1133 utf_display(fmi->classref->name);
1135 utf_display(fmi->name);
1137 utf_display(fmi->descriptor);
1141 case CONSTANT_String:
1142 printf("String -> ");
1145 case CONSTANT_Integer:
1146 printf("Integer -> %d", (int) (((constant_integer*)e)->value));
1148 case CONSTANT_Float:
1149 printf("Float -> %f", ((constant_float*)e)->value);
1151 case CONSTANT_Double:
1152 printf("Double -> %f", ((constant_double*)e)->value);
1156 u8 v = ((constant_long*)e)->value;
1158 printf("Long -> %ld", (long int) v);
1160 printf("Long -> HI: %ld, LO: %ld\n",
1161 (long int) v.high, (long int) v.low);
1165 case CONSTANT_NameAndType:
1167 constant_nameandtype *cnt = e;
1168 printf("NameAndType: ");
1169 utf_display(cnt->name);
1171 utf_display(cnt->descriptor);
1179 log_text("Invalid type of ConstantPool-Entry");
1187 void class_showconstantpool (classinfo *c)
1192 printf ("---- dump of constant pool ----\n");
1194 for (i=0; i<c->cpcount; i++) {
1195 printf ("#%d: ", (int) i);
1197 e = c -> cpinfos [i];
1200 switch (c -> cptags [i]) {
1201 case CONSTANT_Class:
1202 printf ("Classreference -> ");
1203 utf_display ( ((constant_classref*)e) -> name );
1206 case CONSTANT_Fieldref:
1207 printf ("Fieldref -> "); goto displayFMI;
1208 case CONSTANT_Methodref:
1209 printf ("Methodref -> "); goto displayFMI;
1210 case CONSTANT_InterfaceMethodref:
1211 printf ("InterfaceMethod -> "); goto displayFMI;
1214 constant_FMIref *fmi = e;
1215 utf_display ( fmi->classref->name );
1217 utf_display ( fmi->name);
1219 utf_display ( fmi->descriptor );
1223 case CONSTANT_String:
1224 printf ("String -> ");
1227 case CONSTANT_Integer:
1228 printf ("Integer -> %d", (int) ( ((constant_integer*)e) -> value) );
1230 case CONSTANT_Float:
1231 printf ("Float -> %f", ((constant_float*)e) -> value);
1233 case CONSTANT_Double:
1234 printf ("Double -> %f", ((constant_double*)e) -> value);
1238 u8 v = ((constant_long*)e) -> value;
1240 printf ("Long -> %ld", (long int) v);
1242 printf ("Long -> HI: %ld, LO: %ld\n",
1243 (long int) v.high, (long int) v.low);
1247 case CONSTANT_NameAndType:
1249 constant_nameandtype *cnt = e;
1250 printf ("NameAndType: ");
1251 utf_display (cnt->name);
1253 utf_display (cnt->descriptor);
1257 printf ("Utf8 -> ");
1261 log_text("Invalid type of ConstantPool-Entry");
1272 /********** Function: class_showmethods (debugging only) *************/
1274 void class_showmethods (classinfo *c)
1278 printf ("--------- Fields and Methods ----------------\n");
1279 printf ("Flags: "); printflags (c->flags); printf ("\n");
1281 printf ("This: "); utf_display (c->name); printf ("\n");
1283 printf ("Super: "); utf_display (c->super.cls->name); printf ("\n");
1285 printf ("Index: %d\n", c->index);
1287 printf ("interfaces:\n");
1288 for (i=0; i < c-> interfacescount; i++) {
1290 utf_display (c -> interfaces[i].cls -> name);
1291 printf (" (%d)\n", c->interfaces[i].cls -> index);
1294 printf ("fields:\n");
1295 for (i=0; i < c -> fieldscount; i++) {
1296 field_display (&(c -> fields[i]));
1299 printf ("methods:\n");
1300 for (i=0; i < c -> methodscount; i++) {
1301 methodinfo *m = &(c->methods[i]);
1302 if ( !(m->flags & ACC_STATIC))
1303 printf ("vftblindex: %d ", m->vftblindex);
1305 method_display ( m );
1309 printf ("Virtual function table:\n");
1310 for (i=0; i<c->vftbl->vftbllength; i++) {
1311 printf ("entry: %d, %ld\n", i, (long int) (c->vftbl->table[i]) );
1318 * These are local overrides for various environment variables in Emacs.
1319 * Please do not remove this and leave it at the end of the file, where
1320 * Emacs will automagically detect them.
1321 * ---------------------------------------------------------------------
1324 * indent-tabs-mode: t