CACAO
class.cpp
Go to the documentation of this file.
1 /* src/vm/class.cpp - class related functions
2 
3  Copyright (C) 1996-2014
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 #include "vm/class.hpp"
26 
27 #include "config.h"
28 
29 #include <assert.h>
30 #include <inttypes.h> // for PRId64
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 
35 #include "arch.hpp"
36 
37 #include "mm/memory.hpp"
38 
39 #include "native/llni.hpp"
40 
41 #include "threads/lock.hpp"
42 #include "threads/lockword.hpp" // for Lockword
43 #include "threads/mutex.hpp"
44 #include "threads/thread.hpp" // for thread_get_current, etc
45 
46 #include "toolbox/OStream.hpp" // for OStream
47 #include "toolbox/hashtable.hpp" // for hashtable
48 #include "toolbox/logging.hpp"
49 
50 #include "vm/annotation.hpp"
51 #include "vm/array.hpp"
52 #include "vm/class.hpp"
53 #include "vm/classcache.hpp"
54 #include "vm/exceptions.hpp"
55 #include "vm/field.hpp" // for fieldinfo, etc
56 #include "vm/global.hpp"
57 #include "vm/globals.hpp"
58 #include "vm/javaobjects.hpp"
59 #include "vm/linker.hpp"
60 #include "vm/loader.hpp"
61 #include "vm/method.hpp" // for methodinfo, etc
62 #include "vm/options.hpp"
63 #include "vm/primitive.hpp" // for Primitive
64 #include "vm/resolve.hpp"
65 #include "vm/statistics.hpp"
66 #include "vm/string.hpp" // for JavaString
67 #include "vm/suck.hpp"
68 #include "vm/string.hpp"
69 #include "vm/types.hpp"
70 #include "vm/utf8.hpp"
71 
72 #include "vm/jit/builtin.hpp"
73 
74 STAT_DECLARE_GROUP(info_struct_stat)
75 STAT_DECLARE_VAR(int,size_classinfo,0)
76 
77 using namespace cacao;
78 
79 /**
80  * Returns the classname of the class, where slashes ('/') are
81  * replaced by dots ('.').
82  *
83  * @param c class to get name of
84  * @return classname
85  */
87 {
88  return JavaString::from_utf8_slash_to_dot(c->name);
89 }
90 
91 
92 /* class_set_packagename *******************************************************
93 
94  Derive the package name from the class name and store it in the
95  struct.
96 
97  For classes in the unnamed package, the package name is set to
98  NULL.
99 
100 *******************************************************************************/
101 
103 {
104  Utf8String name = c->name;
105 
106  const char *p = name.end() - 1;
107  const char *start = name.begin();
108 
109  if (name[0] == '[') {
110  /* Set packagename of arrays to the element's package. */
111 
112  for (; *start == '['; start++);
113 
114  /* Skip the 'L' in arrays of references. */
115 
116  if (*start == 'L')
117  start++;
118  }
119 
120  /* Search for last '/'. */
121 
122  for (; (p > start) && (*p != '/'); --p);
123 
124  /* If we found a '/' we set the package name. Otherwise we set the
125  packagename to NULL. */
126 
127  if (p > start)
128  c->packagename = Utf8String::from_utf8_slash_to_dot(start, p - start);
129  else
130  c->packagename = NULL;
131 }
132 
133 
134 /* class_create_classinfo ******************************************************
135 
136  Create a new classinfo struct. The class name is set to the given utf string,
137  most other fields are initialized to zero.
138 
139  Note: classname may be NULL. In this case a not-yet-named classinfo is
140  created. The name must be filled in later and class_set_packagename
141  must be called after that.
142 
143 *******************************************************************************/
144 
146 {
147  classinfo *c;
148 
149  STATISTICS(size_classinfo += sizeof(classinfo));
150 
151  /* we use a safe name for temporarily unnamed classes */
152 
153  if (classname == NULL)
154  classname = utf8::not_named_yet;
155 
156 #if !defined(NDEBUG)
157  if (initverbose)
158  log_message_utf("Creating class: ", classname);
159 #endif
160 
161 #if !defined(ENABLE_GC_BOEHM)
163  /*c = NEW(classinfo);
164  MZERO(c, classinfo, 1);*/
165 #else
167  /* GCNEW_UNCOLLECTABLE clears the allocated memory */
168 #endif
169 
170  c->name = classname;
171 
172  /* Set the header.vftbl of all loaded classes to the one of
173  java.lang.Class, so Java code can use a class as object. */
174 
175  if (class_java_lang_Class != NULL)
176  if (class_java_lang_Class->vftbl != NULL)
178 
179 #if defined(ENABLE_JAVASE)
180  /* check if the class is a reference class and flag it */
181 
182  if (classname == utf8::java_lang_ref_SoftReference) {
184  }
185  else if (classname == utf8::java_lang_ref_WeakReference) {
187  }
188  else if (classname == utf8::java_lang_ref_PhantomReference) {
190  }
191 #endif
192 
193  if (classname != utf8::not_named_yet)
195 
197 
198  return c;
199 }
200 
201 
202 /* class_postset_header_vftbl **************************************************
203 
204  Set the header.vftbl of all classes created before java.lang.Class
205  was linked. This is necessary that Java code can use a class as
206  object.
207 
208 *******************************************************************************/
209 
211 {
212  classinfo *c;
213  u4 slot;
214  classcache_name_entry *nmen;
215  classcache_class_entry *clsen;
216 
217  assert(class_java_lang_Class);
218 
219  for (slot = 0; slot < hashtable_classcache.size; slot++) {
221 
222  for (; nmen; nmen = nmen->hashlink) {
223  /* iterate over all class entries */
224 
225  for (clsen = nmen->classes; clsen; clsen = clsen->next) {
226  c = clsen->classobj;
227 
228  /* now set the the vftbl */
229 
230  if (c->object.header.vftbl == NULL)
232  }
233  }
234  }
235 }
236 
237 /* class_define ****************************************************************
238 
239  Calls the loader and defines a class in the VM.
240 
241 *******************************************************************************/
242 
244 {
245  if (name != NULL) {
246  /* check if this class has already been defined */
247 
249 
250  if (c != NULL) {
251  exceptions_throw_linkageerror("duplicate class definition: ", c);
252  return NULL;
253  }
254  }
255 
256  /* create a new classinfo struct */
257 
259 
260 #if defined(ENABLE_STATISTICS)
261  /* measure time */
262 
263  if (opt_getloadingtime)
265 #endif
266 
267  /* preset the defining classloader */
268 
269  c->classloader = cl;
270 
271  /* build a classbuffer with the given data */
272 
273  ClassBuffer cb(c, data, length);
274 
275  /* load the class from this buffer */
276 
278 
279 #if defined(ENABLE_STATISTICS)
280  /* measure time */
281 
282  if (opt_getloadingtime)
284 #endif
285 
286  if (r == NULL) {
287  /* If return value is NULL, we had a problem and the class is
288  not loaded. Now free the allocated memory, otherwise we
289  could run into a DOS. */
290 
291  class_free(c);
292 
293  return NULL;
294  }
295 
296 #if defined(ENABLE_JAVASE)
297 # if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
298  /* Store the protection domain. */
299 
300  c->protectiondomain = pd;
301 # endif
302 #endif
303 
304  /* Store the newly defined class in the class cache. This call
305  also checks whether a class of the same name has already been
306  defined by the same defining loader, and if so, replaces the
307  newly created class by the one defined earlier. */
308 
309  /* Important: The classinfo given to classcache_store must be
310  fully prepared because another thread may return
311  this pointer after the lookup at to top of this
312  function directly after the class cache lock has
313  been released. */
314 
315  c = classcache_store(cl, c, true);
316 
317 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7)
319  jlc.set_classLoader(cl);
320 #endif
321 
322  return c;
323 }
324 
325 
326 /* class_load_attribute_sourcefile *********************************************
327 
328  SourceFile_attribute {
329  u2 attribute_name_index;
330  u4 attribute_length;
331  u2 sourcefile_index;
332  }
333 
334 *******************************************************************************/
335 
337 {
338  /* get classinfo */
339 
340  classinfo *c = cb.get_class();
341 
342  /* check buffer size */
343 
344  if (!cb.check_size(4 + 2))
345  return false;
346 
347  /* check attribute length */
348 
349  u4 attribute_length = cb.read_u4();
350 
351  if (attribute_length != 2) {
352  exceptions_throw_classformaterror(c, "Wrong size for VALUE attribute");
353  return false;
354  }
355 
356  /* there can be no more than one SourceFile attribute */
357 
358  if (c->sourcefile != NULL) {
359  exceptions_throw_classformaterror(c, "Multiple SourceFile attributes");
360  return false;
361  }
362 
363  /* get sourcefile */
364 
365  u2 sourcefile_index = cb.read_u2();
366  Utf8String sourcefile = (utf*) class_getconstant(c, sourcefile_index, CONSTANT_Utf8);
367 
368  if (sourcefile == NULL)
369  return false;
370 
371  /* store sourcefile */
372 
373  c->sourcefile = sourcefile;
374 
375  return true;
376 }
377 
378 
379 /* class_load_attribute_enclosingmethod ****************************************
380 
381  EnclosingMethod_attribute {
382  u2 attribute_name_index;
383  u4 attribute_length;
384  u2 class_index;
385  u2 method_index;
386  }
387 
388 *******************************************************************************/
389 
390 #if defined(ENABLE_JAVASE)
393 
394  /* get classinfo */
395 
396  classinfo *c = cb.get_class();
397 
398  /* check buffer size */
399 
400  if (!cb.check_size(4 + 2 + 2))
401  return false;
402 
403  /* check attribute length */
404 
405  u4 attribute_length = cb.read_u4();
406 
407  if (attribute_length != 4) {
408  exceptions_throw_classformaterror(c, "Wrong size for VALUE attribute");
409  return false;
410  }
411 
412  /* there can be no more than one EnclosingMethod attribute */
413 
414  if (c->enclosingmethod != NULL) {
415  exceptions_throw_classformaterror(c, "Multiple EnclosingMethod attributes");
416  return false;
417  }
418 
419  /* get class index */
420 
421  u2 class_index = cb.read_u2();
423 
424  /* get method index */
425 
426  u2 method_index = cb.read_u2();
428 
429  /* store info in classinfo */
430 
431  c->enclosingclass.any = cr.any;
432  c->enclosingmethod = cn;
433 
434  return true;
435 }
436 #endif /* defined(ENABLE_JAVASE) */
437 
438 
439 /* class_load_attributes *******************************************************
440 
441  Read attributes from ClassFile.
442 
443  attribute_info {
444  u2 attribute_name_index;
445  u4 attribute_length;
446  u1 info[attribute_length];
447  }
448 
449  InnerClasses_attribute {
450  u2 attribute_name_index;
451  u4 attribute_length;
452  }
453 
454 *******************************************************************************/
455 
457 {
458  classref_or_classinfo outer, inner;
459 
460  classinfo *c = cb.get_class();
461 
462  /* get attributes count */
463 
464  if (!cb.check_size(2))
465  return false;
466 
467  uint16_t attributes_count = cb.read_u2();
468 
469  for (int i = 0; i < attributes_count; i++) {
470  /* get attribute name */
471 
472  if (!cb.check_size(2))
473  return false;
474 
475  uint16_t attribute_name_index = cb.read_u2();
476  Utf8String attribute_name = (utf*) class_getconstant(c, attribute_name_index, CONSTANT_Utf8);
477 
478  if (attribute_name == NULL)
479  return false;
480 
481  if (attribute_name == utf8::InnerClasses) {
482  /* InnerClasses */
483 
484  if (c->innerclass != NULL) {
485  exceptions_throw_classformaterror(c, "Multiple InnerClasses attributes");
486  return false;
487  }
488 
489  if (!cb.check_size(4 + 2))
490  return false;
491 
492  /* skip attribute length */
493  cb.read_u4();
494 
495  /* number of records */
496  c->innerclasscount = cb.read_u2();
497 
498  if (!cb.check_size((2 + 2 + 2 + 2) * c->innerclasscount))
499  return false;
500 
501  /* allocate memory for innerclass structure */
503 
504  for (int j = 0; j < c->innerclasscount; j++) {
505  /* The innerclass structure contains a class with an encoded
506  name, its defining scope, its simple name and a bitmask of
507  the access flags. */
508 
509  innerclassinfo *info = c->innerclass + j;
510 
514  uint16_t flags = cb.read_u2();
515 
516  /* If the current inner-class is the currently loaded
517  class check for some special flags. */
518 
519  if (inner.ref->name == c->name) {
520  /* If an inner-class is not a member, its
521  outer-class is NULL. */
522 
523  if (outer.ref != NULL) {
524  c->flags |= ACC_CLASS_MEMBER;
525 
526  /* A member class doesn't have an
527  EnclosingMethod attribute, so set the
528  enclosing-class to be the same as the
529  declaring-class. */
530 
531  c->declaringclass = outer;
532  c->enclosingclass = outer;
533  }
534 
535  /* If an inner-class is anonymous, its name is
536  NULL. */
537 
538  if (name == NULL)
540  }
541 
542  info->inner_class = inner;
543  info->outer_class = outer;
544  info->name = name;
545  info->flags = flags;
546  }
547  }
548  else if (attribute_name == utf8::SourceFile) {
549  /* SourceFile */
550 
552  return false;
553  }
554 #if defined(ENABLE_JAVASE)
555  else if (attribute_name == utf8::EnclosingMethod) {
556  /* EnclosingMethod */
557 
559  return false;
560  }
561  else if (attribute_name == utf8::Signature) {
562  /* Signature */
563 
564  // TODO: change classinfo.signature to Utf8String
565  // and use it directly
566 
567  Utf8String signature = c->signature;
568 
569  if (!loader_load_attribute_signature(cb, signature)) {
570  return false;
571  }
572 
573  c->signature = signature;
574  }
575 #endif
576 
577 #if defined(ENABLE_ANNOTATIONS)
578  else if (attribute_name == utf8::RuntimeVisibleAnnotations) {
579  /* RuntimeVisibleAnnotations */
581  return false;
582  }
583  else if (attribute_name == utf8::RuntimeInvisibleAnnotations) {
584  /* RuntimeInvisibleAnnotations */
586  return false;
587  }
588 #endif
589 
590  else {
591  /* unknown attribute */
592 
594  return false;
595  }
596  }
597 
598  return true;
599 }
600 
601 
602 /* class_freepool **************************************************************
603 
604  Frees all resources used by this classes Constant Pool.
605 
606 *******************************************************************************/
607 
608 static void class_freecpool(classinfo *c)
609 {
610  if (c->cptags && c->cpinfos) {
611  for (int32_t idx = 0; idx < c->cpcount; idx++) {
613  void *info = c->cpinfos[idx];
614 
615  if (info != NULL) {
616  switch (tag) {
617  case CONSTANT_Class:
618  case CONSTANT_ClassName:
619  case CONSTANT_String:
620  case CONSTANT_Utf8:
621  // these live forever
622  break;
623 
624  case CONSTANT_Fieldref:
625  case CONSTANT_Methodref:
627  FREE(info, constant_FMIref);
628  break;
629  case CONSTANT_Integer:
630  FREE(info, int32_t);
631  break;
632  case CONSTANT_Float:
633  FREE(info, float);
634  break;
635  case CONSTANT_Long:
636  FREE(info, int64_t);
637  break;
638  case CONSTANT_Double:
639  FREE(info, double);
640  break;
642  FREE(info, constant_nameandtype);
643  break;
644 
645  case CONSTANT_MethodType:
646  delete ((constant_MethodType*) info);
647  break;
649  delete ((constant_MethodHandle*) info);
650  break;
652  delete ((constant_InvokeDynamic*) info);
653  break;
654 
655  case CONSTANT_UNUSED:
656  assert(info == 0);
657  break;
658  }
659  }
660  }
661  }
662 
663  if (c->cptags)
664  MFREE(c->cptags, u1, c->cpcount);
665 
666  if (c->cpinfos)
667  MFREE(c->cpinfos, void*, c->cpcount);
668 }
669 
670 
671 /* class_getconstant ***********************************************************
672 
673  Retrieves the value at position 'pos' of the constantpool of a
674  class. If the type of the value is other than 'ctype', an error is
675  thrown.
676 
677 *******************************************************************************/
678 
680 {
681  // check index and type of constantpool entry
682  // (pos == 0 is caught by type comparison)
683 
684  if ((((int32_t)pos) >= c->cpcount) || (c->cptags[pos] != ctype)) {
685  // this is the slow path,
686  // we can afford to repeat the separate checks for a better error message
687 
688  if ((pos == 0) || (((int32_t)pos) >= c->cpcount)) {
689  exceptions_throw_classformaterror(c, "Illegal constant pool index: %u", pos);
690  } else if (c->cptags[pos] != ctype) {
691  exceptions_throw_classformaterror(c, "Illegal constant pool type %u (expected %u)", ctype, c->cptags[pos]);
692  }
693 
694  assert(exceptions_get_exception());
695  return NULL;
696  }
697 
698  return c->cpinfos[pos];
699 }
700 
701 
702 /* innerclass_getconstant ******************************************************
703 
704  Like class_getconstant, but if cptags is ZERO, null is returned.
705 
706 *******************************************************************************/
707 
709 {
710  /* invalid position in constantpool */
711 
712  if (((int32_t)pos) >= c->cpcount) {
713  exceptions_throw_classformaterror(c, "Illegal constant pool index: %u", pos);
714  return NULL;
715  }
716 
717  /* constantpool entry of type 0 */
718 
719  if (c->cptags[pos] == 0)
720  return NULL;
721 
722  /* check type of constantpool entry */
723 
724  if (c->cptags[pos] != ctype) {
725  exceptions_throw_classformaterror(c, "Illegal constant pool type %u (expected %u)", ctype, c->cptags[pos]);
726  return NULL;
727  }
728 
729  return c->cpinfos[pos];
730 }
731 
732 
733 /* class_free ******************************************************************
734 
735  Frees all resources used by the class.
736 
737 *******************************************************************************/
738 
740 {
741  class_freecpool(c);
742 
743  if (c->interfaces != NULL)
745 
746  if (c->fields) {
747  for (int32_t i = 0; i < c->fieldscount; i++)
748  field_free(&(c->fields[i]));
750  }
751 
752  if (c->methods) {
753  for (int32_t i = 0; i < c->methodscount; i++)
754  method_free(&(c->methods[i]));
756  }
757 
758  if (vftbl_t *v = c->vftbl) {
759  if (v->arraydesc)
760  mem_free(v->arraydesc,sizeof(arraydescriptor));
761 
762  for (int32_t i = 0; i < v->interfacetablelength; i++) {
763  MFREE(v->interfacetable[-i], methodptr, v->interfacevftbllength[i]);
764  }
765  MFREE(v->interfacevftbllength, s4, v->interfacetablelength);
766 
767  int32_t i = sizeof(vftbl_t)
768  + sizeof(methodptr) * (v->vftbllength - 1)
769  + sizeof(methodptr*) * (v->interfacetablelength - (v->interfacetablelength > 0));
770  methodptr *m = ((methodptr*) v) - (v->interfacetablelength - 1) * (v->interfacetablelength > 1);
771  mem_free(m, i);
772  }
773 
774  if (c->innerclass)
776 
777  /* if (c->classvftbl)
778  mem_free(c->header.vftbl, sizeof(vftbl) + sizeof(methodptr)*(c->vftbl->vftbllength-1)); */
779 
780 /* GCFREE(c); */
781 }
782 
783 
784 /* get_array_class *************************************************************
785 
786  Returns the array class with the given name for the given
787  classloader, or NULL if an exception occurred.
788 
789  Note: This function does eager loading.
790 
791 *******************************************************************************/
792 
794  classloader_t *defloader,bool link)
795 {
796  classinfo *c;
797 
798  /* lookup this class in the classcache */
799  c = classcache_lookup(initloader,name);
800  if (!c)
801  c = classcache_lookup_defined(defloader,name);
802 
803  if (!c) {
804  /* we have to create it */
805  c = class_create_classinfo(name);
806  c = load_newly_created_array(c,initloader);
807  if (c == NULL)
808  return NULL;
809  }
810 
811  assert(c);
812  assert(c->state & CLASS_LOADED);
813  assert(c->classloader == defloader);
814 
815  if (link && !(c->state & CLASS_LINKED))
816  if (!link_class(c))
817  return NULL;
818 
819  assert(!link || (c->state & CLASS_LINKED));
820 
821  return c;
822 }
823 
824 
825 /* class_array_of **************************************************************
826 
827  Returns an array class with the given component class. The array
828  class is dynamically created if neccessary.
829 
830 *******************************************************************************/
831 
833 {
834  classloader_t *cl;
835  s4 namelen;
836  char *namebuf;
837  Utf8String u;
838  classinfo *c;
839 
840  Utf8String component_name = component->name;
841 
842  cl = component->classloader;
843 
844  /* Assemble the array class name */
845  namelen = component_name.size();
846 
847  if (component_name[0] == '[') {
848  /* the component is itself an array */
849  namebuf = MNEW(char, namelen + 1);
850  namebuf[0] = '[';
851  MCOPY(namebuf + 1, component_name.begin(), char, namelen);
852  namelen++;
853  }
854  else {
855  /* the component is a non-array class */
856  namebuf = MNEW(char, namelen + 3);
857  namebuf[0] = '[';
858  namebuf[1] = 'L';
859  MCOPY(namebuf + 2, component_name.begin(), char, namelen);
860  namebuf[2 + namelen] = ';';
861  namelen += 3;
862  }
863 
864  u = Utf8String::from_utf8(namebuf, namelen);
865 
866  MFREE(namebuf, char, namelen);
867 
868  c = get_array_class(u, cl, cl, link);
869 
870  return c;
871 }
872 
873 
874 /* class_multiarray_of *********************************************************
875 
876  Returns an array class with the given dimension and element class.
877  The array class is dynamically created if neccessary.
878 
879 *******************************************************************************/
880 
882 {
883  s4 namelen;
884  char *namebuf;
885  classinfo *c;
886 
887  Utf8String element_name = element->name;
888 
889  if (dim < 1) {
890  log_text("Invalid array dimension requested");
891  assert(0);
892  }
893 
894  /* Assemble the array class name */
895  namelen = element_name.size();
896 
897  if (element_name[0] == '[') {
898  /* the element is itself an array */
899  namebuf = MNEW(char, namelen + dim);
900  memcpy(namebuf + dim, element_name.begin(), namelen);
901  namelen += dim;
902  }
903  else {
904  /* the element is a non-array class */
905  namebuf = MNEW(char, namelen + 2 + dim);
906  namebuf[dim] = 'L';
907  memcpy(namebuf + dim + 1, element_name.begin(), namelen);
908  namelen += (2 + dim);
909  namebuf[namelen - 1] = ';';
910  }
911  memset(namebuf, '[', dim);
912 
913  Utf8String u = Utf8String::from_utf8(namebuf, namelen);
914 
915  MFREE(namebuf, char, namelen);
916 
917  c = get_array_class(u,
918  element->classloader,
919  element->classloader,
920  link);
921 
922  return c;
923 }
924 
925 
926 /* class_lookup_classref *******************************************************
927 
928  Looks up the constant_classref for a given classname in the classref
929  tables of a class.
930 
931  IN:
932  cls..............the class containing the reference
933  name.............the name of the class refered to
934 
935  RETURN VALUE:
936  a pointer to a constant_classref, or
937  NULL if the reference was not found
938 
939 *******************************************************************************/
940 
942 {
943  constant_classref *ref;
944  extra_classref *xref;
945  int count;
946 
947  assert(cls);
948  assert(name);
949  assert(!cls->classrefcount || cls->classrefs);
950 
951  /* first search the main classref table */
952  count = cls->classrefcount;
953  ref = cls->classrefs;
954  for (; count; --count, ++ref)
955  if (ref->name == name)
956  return ref;
957 
958  /* next try the list of extra classrefs */
959  for (xref = cls->extclassrefs; xref; xref = xref->next) {
960  if (xref->classref.name == name)
961  return &(xref->classref);
962  }
963 
964  /* not found */
965  return NULL;
966 }
967 
968 
969 /* class_get_classref **********************************************************
970 
971  Returns the constant_classref for a given classname.
972 
973  IN:
974  cls..............the class containing the reference
975  name.............the name of the class refered to
976 
977  RETURN VALUE:
978  a pointer to a constant_classref (never NULL)
979 
980  NOTE:
981  The given name is not checked for validity!
982 
983 *******************************************************************************/
984 
986 {
987  assert(cls);
988  assert(name);
989 
990  if (constant_classref *ref = class_lookup_classref(cls,name))
991  return ref;
992 
993  extra_classref *xref = new (MemAlloc) extra_classref(cls->extclassrefs, cls, name);
994 
995  cls->extclassrefs = xref;
996 
997  return &(xref->classref);
998 }
999 
1000 
1001 /* class_get_self_classref *****************************************************
1002 
1003  Returns the constant_classref to the class itself.
1004 
1005  IN:
1006  cls..............the class containing the reference
1007 
1008  RETURN VALUE:
1009  a pointer to a constant_classref (never NULL)
1010 
1011 *******************************************************************************/
1012 
1014 {
1015  /* XXX this should be done in a faster way. Maybe always make */
1016  /* the classref of index 0 a self reference. */
1017  return class_get_classref(cls,cls->name);
1018 }
1019 
1020 /* class_get_classref_multiarray_of ********************************************
1021 
1022  Returns an array type reference with the given dimension and element class
1023  reference.
1024 
1025  IN:
1026  dim..............the requested dimension
1027  dim must be in [1;255]. This is NOT checked!
1028  ref..............the component class reference
1029 
1030  RETURN VALUE:
1031  a pointer to the class reference for the array type
1032 
1033  NOTE:
1034  The referer of `ref` is used as the referer for the new classref.
1035 
1036 *******************************************************************************/
1037 
1039 {
1040  s4 namelen;
1041  char *namebuf;
1042  constant_classref *cr;
1043 
1044  Utf8String refname = ref->name;
1045 
1046  assert(ref);
1047  assert(dim >= 1 && dim <= 255);
1048 
1049  /* Assemble the array class name */
1050  namelen = refname.size();
1051 
1052  if (refname[0] == '[') {
1053  /* the element is itself an array */
1054  namebuf = MNEW(char, namelen + dim);
1055  memcpy(namebuf + dim, refname.begin(), namelen);
1056  namelen += dim;
1057  }
1058  else {
1059  /* the element is a non-array class */
1060  namebuf = MNEW(char, namelen + 2 + dim);
1061  namebuf[dim] = 'L';
1062  memcpy(namebuf + dim + 1, refname.begin(), namelen);
1063  namelen += (2 + dim);
1064  namebuf[namelen - 1] = ';';
1065  }
1066  memset(namebuf, '[', dim);
1067 
1068  Utf8String u = Utf8String::from_utf8(namebuf, namelen);
1069 
1070  MFREE(namebuf, char, namelen);
1071 
1072  cr = class_get_classref(ref->referer, u);
1073 
1074  return cr;
1075 }
1076 
1077 
1078 /* class_get_classref_component_of *********************************************
1079 
1080  Returns the component classref of a given array type reference
1081 
1082  IN:
1083  ref..............the array type reference
1084 
1085  RETURN VALUE:
1086  a reference to the component class, or
1087  NULL if `ref` is not an object array type reference
1088 
1089  NOTE:
1090  The referer of `ref` is used as the referer for the new classref.
1091 
1092 *******************************************************************************/
1093 
1095 {
1096  assert(ref);
1097 
1098  Utf8String name = ref->name;
1099  size_t start = 1;
1100  size_t end = name.size() - 1;
1101 
1102  if (name[0] != '[')
1103  return NULL;
1104 
1105  if (name[1] == 'L') {
1106  start += 1;
1107  end -= 2;
1108  }
1109  else if (name[1] != '[') {
1110  return NULL;
1111  }
1112 
1113  return class_get_classref(ref->referer, name.substring(start, end));
1114 }
1115 
1116 
1117 /* class_findmethod ************************************************************
1118 
1119  Searches a 'classinfo' structure for a method having the given name
1120  and descriptor. If descriptor is NULL, it is ignored.
1121 
1122 *******************************************************************************/
1123 
1125 {
1126  for (int32_t i = 0; i < c->methodscount; i++) {
1127  methodinfo *m = &(c->methods[i]);
1128 
1129  if ((m->name == name) && ((desc == NULL) || (m->descriptor == desc)))
1130  return m;
1131  }
1132 
1133  return NULL;
1134 }
1135 
1136 
1137 /* class_resolvemethod *********************************************************
1138 
1139  Searches a class and it's super classes for a method.
1140 
1141  Superinterfaces are *not* searched.
1142 
1143 *******************************************************************************/
1144 
1146 {
1147  while (c) {
1148  methodinfo *m = class_findmethod(c, name, desc);
1149 
1150  if (m)
1151  return m;
1152 
1153  /* JVM Specification bug:
1154 
1155  It is important NOT to resolve special <init> and <clinit>
1156  methods to super classes or interfaces; yet, this is not
1157  explicited in the specification. Section 5.4.3.3 should be
1158  updated appropriately. */
1159 
1160  if (name == utf8::init || name == utf8::clinit)
1161  return NULL;
1162 
1163  c = c->super;
1164  }
1165 
1166  return NULL;
1167 }
1168 
1169 
1170 /* class_resolveinterfacemethod_intern *****************************************
1171 
1172  Internally used helper function. Do not use this directly.
1173 
1174 *******************************************************************************/
1175 
1177  Utf8String name, Utf8String desc)
1178 {
1179  /* try to find the method in the class */
1180 
1181  methodinfo *m = class_findmethod(c, name, desc);
1182 
1183  if (m != NULL)
1184  return m;
1185 
1186  /* No method found? Try the super interfaces. */
1187 
1188  for (int32_t i = 0; i < c->interfacescount; i++) {
1190 
1191  if (m != NULL)
1192  return m;
1193  }
1194 
1195  /* no method found */
1196 
1197  return NULL;
1198 }
1199 
1200 
1201 /* class_resolveclassmethod ****************************************************
1202 
1203  Resolves a reference from REFERER to a method with NAME and DESC in
1204  class C.
1205 
1206  If the method cannot be resolved the return value is NULL. If
1207  EXCEPT is true *exceptionptr is set, too.
1208 
1209 *******************************************************************************/
1210 
1212  classinfo *referer, bool throwexception)
1213 {
1214  /* try class c and its superclasses */
1215 
1216  classinfo *cls = c;
1217 
1218  methodinfo *m = class_resolvemethod(cls, name, desc);
1219 
1220  if (m != NULL)
1221  goto found;
1222 
1223  /* Try the super interfaces. */
1224 
1225  for (int32_t i = 0; i < c->interfacescount; i++) {
1227 
1228  if (m != NULL)
1229  goto found;
1230  }
1231 
1232  if (throwexception)
1233  exceptions_throw_nosuchmethoderror(c, name, desc);
1234 
1235  return NULL;
1236 
1237  found:
1238  if ((m->flags & ACC_ABSTRACT) && !(c->flags & ACC_ABSTRACT)) {
1239  if (throwexception)
1241 
1242  return NULL;
1243  }
1244 
1245  /* XXX check access rights */
1246 
1247  return m;
1248 }
1249 
1250 
1251 /* class_resolveinterfacemethod ************************************************
1252 
1253  Resolves a reference from REFERER to a method with NAME and DESC in
1254  interface C.
1255 
1256  If the method cannot be resolved the return value is NULL. If
1257  EXCEPT is true *exceptionptr is set, too.
1258 
1259 *******************************************************************************/
1260 
1262  classinfo *referer, bool throwexception)
1263 {
1264  methodinfo *mi;
1265 
1266  if (!(c->flags & ACC_INTERFACE)) {
1267  if (throwexception)
1268  exceptions_throw_incompatibleclasschangeerror(c, "Not an interface");
1269 
1270  return NULL;
1271  }
1272 
1273  mi = class_resolveinterfacemethod_intern(c, name, desc);
1274 
1275  if (mi != NULL)
1276  return mi;
1277 
1278  /* try class java.lang.Object */
1279 
1280  mi = class_findmethod(class_java_lang_Object, name, desc);
1281 
1282  if (mi != NULL)
1283  return mi;
1284 
1285  if (throwexception)
1286  exceptions_throw_nosuchmethoderror(c, name, desc);
1287 
1288  return NULL;
1289 }
1290 
1291 
1292 /* class_findfield *************************************************************
1293 
1294  Searches for field with specified name and type in a classinfo
1295  structure. If no such field is found NULL is returned.
1296 
1297 *******************************************************************************/
1298 
1300 {
1301  for (int32_t i = 0; i < c->fieldscount; i++)
1302  if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc))
1303  return &(c->fields[i]);
1304 
1305  if (c->super != NULL)
1306  return class_findfield(c->super, name, desc);
1307 
1308  return NULL;
1309 }
1310 
1311 
1312 /* class_findfield_approx ******************************************************
1313 
1314  Searches in 'classinfo'-structure for a field with the specified
1315  name.
1316 
1317 *******************************************************************************/
1318 
1320 {
1321  for (int32_t i = 0; i < c->fieldscount; i++) {
1322  fieldinfo* f = &(c->fields[i]);
1323 
1324  if (f->name == name)
1325  return f;
1326  }
1327 
1328  // Field not found.
1329  if (throwexception)
1331  return NULL;
1332 }
1333 
1334 
1335 /****************** Function: class_resolvefield_int ***************************
1336 
1337  This is an internally used helper function. Do not use this directly.
1338 
1339  Tries to resolve a field having the given name and type.
1340  If the field cannot be resolved, NULL is returned.
1341 
1342 *******************************************************************************/
1343 
1345 {
1346  /* search for field in class c */
1347 
1348  for (int32_t i = 0; i < c->fieldscount; i++) {
1349  if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc)) {
1350  return &(c->fields[i]);
1351  }
1352  }
1353 
1354  /* Try super interfaces recursively. */
1355 
1356  for (int32_t i = 0; i < c->interfacescount; i++) {
1357  fieldinfo *fi = class_resolvefield_int(c->interfaces[i], name, desc);
1358 
1359  if (fi != NULL)
1360  return fi;
1361  }
1362 
1363  /* Try super class. */
1364 
1365  if (c->super != NULL)
1366  return class_resolvefield_int(c->super, name, desc);
1367 
1368  /* not found */
1369 
1370  return NULL;
1371 }
1372 
1373 
1374 /********************* Function: class_resolvefield ***************************
1375 
1376  Resolves a reference from REFERER to a field with NAME and DESC in class C.
1377 
1378  If the field cannot be resolved, an exception is thrown and the
1379  return value is NULL.
1380 
1381 *******************************************************************************/
1382 
1384 {
1385  fieldinfo *fi = class_resolvefield_int(c, name, desc);
1386 
1387  if (!fi) {
1389  return NULL;
1390  }
1391 
1392  /* XXX check access rights */
1393 
1394  return fi;
1395 }
1396 
1397 
1398 /* class_issubclass ************************************************************
1399 
1400  Checks if sub is a descendant of super.
1401 
1402 *******************************************************************************/
1403 
1405 {
1406  classinfo *c = sub;
1407 
1408  for (;;) {
1409  /* We reached java/lang/Object and did not find the requested
1410  super class. */
1411 
1412  if (c == NULL)
1413  return false;
1414 
1415  /* We found the requested super class. */
1416 
1417  if (c == super)
1418  return true;
1419 
1420  c = c->super;
1421  }
1422 }
1423 
1424 
1425 /* class_isanysubclass *********************************************************
1426 
1427  Checks a subclass relation between two classes. Implemented
1428  interfaces are interpreted as super classes.
1429 
1430  Return value: 1 ... sub is subclass of super
1431  0 ... otherwise
1432 
1433 *******************************************************************************/
1434 
1436 {
1437  bool result;
1438 
1439  /* This is the trivial case. */
1440 
1441  if (sub == super)
1442  return true;
1443 
1444  /* Primitive classes are only subclasses of themselves. */
1445 
1446  if (class_is_primitive(sub) || class_is_primitive(super))
1447  return false;
1448 
1449  /* Check for interfaces. */
1450 
1451  if (super->flags & ACC_INTERFACE) {
1452  result = (sub->vftbl->interfacetablelength > super->index) &&
1453  (sub->vftbl->interfacetable[-super->index] != NULL);
1454  }
1455  else {
1456  /* java.lang.Object is the only super class of any
1457  interface. */
1458 
1459  if (sub->state & ACC_INTERFACE)
1460  return (super == class_java_lang_Object);
1461 
1462 #if USES_NEW_SUBTYPE
1463  result = fast_subtype_check(sub->vftbl, super->vftbl);
1464 #else
1466 
1467  uint32_t diffval = sub->vftbl->baseval - super->vftbl->baseval;
1468  result = diffval <= (uint32_t) super->vftbl->diffval;
1469 
1471 #endif
1472  }
1473 
1474  return result;
1475 }
1476 
1477 
1478 /* class_is_arraycompatible ****************************************************
1479 
1480  Checks if two array type descriptors are assignment compatible.
1481 
1482  RETURN VALUE:
1483  true .... target = desc is possible
1484  false ... otherwise
1485 
1486 *******************************************************************************/
1487 
1489 {
1490  if (desc == target)
1491  return true;
1492 
1493  if (desc->arraytype != target->arraytype)
1494  return false;
1495 
1496  if (desc->arraytype != ARRAYTYPE_OBJECT)
1497  return true;
1498 
1499  /* {both arrays are arrays of references} */
1500 
1501  if (desc->dimension == target->dimension) {
1502  if (!desc->elementvftbl)
1503  return false;
1504 
1505  /* an array which contains elements of interface types is
1506  allowed to be casted to array of Object (JOWENN) */
1507 
1508  if ((desc->elementvftbl->baseval < 0) &&
1509  (target->elementvftbl->baseval == 1))
1510  return true;
1511 
1512  return class_isanysubclass(desc->elementvftbl->clazz, target->elementvftbl->clazz);
1513  }
1514 
1515  if (desc->dimension < target->dimension)
1516  return false;
1517 
1518  /* {desc has higher dimension than target} */
1519 
1521 }
1522 
1523 
1524 /* class_is_assignable_from ****************************************************
1525 
1526  Return whether an instance of the "from" class parameter would be
1527  an instance of this class "to" as well.
1528 
1529  ARGUMENTS:
1530  to ..... class
1531  from ... class
1532 
1533  RETURN:
1534  true .... is assignable
1535  false ... is not assignable
1536 
1537 *******************************************************************************/
1538 
1540 {
1541  if (!(to->state & CLASS_LINKED))
1542  if (!link_class(to))
1543  return false;
1544 
1545  if (!(from->state & CLASS_LINKED))
1546  if (!link_class(from))
1547  return false;
1548 
1549  /* Decide whether we are dealing with array types or object types. */
1550 
1551  if (class_is_array(to) && class_is_array(from))
1553  else
1554  return class_isanysubclass(from, to);
1555 }
1556 
1557 
1558 /* class_is_instance ***********************************************************
1559 
1560  Return if the given Java object is an instance of the given class.
1561 
1562  ARGUMENTS:
1563  c ... class
1564  h ... Java object
1565 
1566  RETURN:
1567  true .... is instance
1568  false ... is not instance
1569 
1570 *******************************************************************************/
1571 
1573 {
1574  if (!(c->state & CLASS_LINKED))
1575  if (!link_class(c))
1576  return false;
1577 
1578  /* Decide whether we are dealing with array types or object types. */
1579 
1580  if (class_is_array(c))
1581  return builtin_arrayinstanceof(h, c);
1582  else
1583  return builtin_instanceof(h, c);
1584 }
1585 
1586 
1587 /* class_get_componenttype *****************************************************
1588 
1589  Return the component class of the given class. If the given class
1590  is not an array, return NULL.
1591 
1592 *******************************************************************************/
1593 
1595 {
1596  classinfo *component;
1597  arraydescriptor *ad;
1598 
1599  /* XXX maybe we could find a way to do this without linking. */
1600  /* This way should be safe and easy, however. */
1601 
1602  if (!(c->state & CLASS_LINKED))
1603  if (!link_class(c))
1604  return NULL;
1605 
1606  ad = c->vftbl->arraydesc;
1607 
1608  if (ad == NULL)
1609  return NULL;
1610 
1611  if (ad->arraytype == ARRAYTYPE_OBJECT)
1612  component = ad->componentvftbl->clazz;
1613  else
1614  component = Primitive::get_class_by_type(ad->arraytype);
1615 
1616  return component;
1617 }
1618 
1619 
1620 /* class_get_declaredclasses ***************************************************
1621 
1622  Return an array of declared classes of the given class.
1623 
1624 *******************************************************************************/
1625 
1627 {
1628  int declaredclasscount = 0; // number of declared classes
1629 
1630  if (!class_is_primitive(c) && !class_is_array(c)) {
1631  /* Determine number of declared classes. */
1632 
1633  for (uint16_t i = 0; i < c->innerclasscount; i++) {
1634  /* Get outer-class. If the inner-class is not a member
1635  class, the outer-class is NULL. */
1636 
1638 
1639  if (outer.any == NULL)
1640  continue;
1641 
1642  /* Check if outer-class is a classref or a real class and
1643  get the class name from the structure. */
1644 
1645  Utf8String outername = CLASSREF_OR_CLASSINFO_NAME(outer);
1646 
1647  /* Outer class is this class. */
1648 
1649  if ((outername == c->name) &&
1650  ((publicOnly == 0) || (c->innerclass[i].flags & ACC_PUBLIC)))
1651  declaredclasscount++;
1652  }
1653  }
1654 
1655  /* Allocate Class[] and check for OOM. */
1656 
1657  ClassArray declaredclasses(declaredclasscount);
1658 
1659  if (declaredclasses.is_null())
1660  return NULL;
1661 
1662  for (uint16_t i = 0, pos = 0; i < c->innerclasscount; i++) {
1665 
1666  /* Get outer-class. If the inner-class is not a member class,
1667  the outer-class is NULL. */
1668 
1669  if (outer.any == NULL)
1670  continue;
1671 
1672  /* Check if outer_class is a classref or a real class and get
1673  the class name from the structure. */
1674 
1675  Utf8String outername = CLASSREF_OR_CLASSINFO_NAME(outer);
1676 
1677  /* Outer class is this class. */
1678 
1679  if ((outername == c->name) &&
1680  ((publicOnly == 0) || (c->innerclass[i].flags & ACC_PUBLIC))) {
1681 
1682  classinfo *ic = resolve_classref_or_classinfo_eager(inner, false);
1683 
1684  if (ic == NULL)
1685  return NULL;
1686 
1687  if (!(ic->state & CLASS_LINKED))
1688  if (!link_class(ic))
1689  return NULL;
1690 
1691  declaredclasses.set_element(pos++, ic);
1692  }
1693  }
1694 
1695  return declaredclasses.get_handle();
1696 }
1697 
1698 
1699 /**
1700  * Return an array of declared constructors of the given class.
1701  *
1702  * @param c class to get the constructors of
1703  * @param publicOnly show only public fields
1704  *
1705  * @return array of java.lang.reflect.Constructor
1706  */
1707 #if defined(ENABLE_JAVASE)
1709 {
1710  /* Determine number of constructors. */
1711 
1712  int count = 0;
1713 
1714  for (int32_t i = 0; i < c->methodscount; i++) {
1715  methodinfo* m = &(c->methods[i]);
1716 
1717  if (((m->flags & ACC_PUBLIC) || (publicOnly == 0)) && (m->name == utf8::init))
1718  count++;
1719  }
1720 
1721  /* Create array of constructors. */
1722 
1724 
1725  if (oa.is_null())
1726  return NULL;
1727 
1728  /* Get the constructors and store them in the array. */
1729 
1730  for (int32_t i = 0, index = 0; i < c->methodscount; i++) {
1731  methodinfo* m = &(c->methods[i]);
1732 
1733  if (((m->flags & ACC_PUBLIC) || (publicOnly == 0)) &&
1734  (m->name == utf8::init)) {
1735  // Create a java.lang.reflect.Constructor object.
1736 
1738 
1739  /* Store object into array. */
1740 
1741  oa.set_element(index, rc.get_handle());
1742  index++;
1743  }
1744  }
1745 
1746  return oa.get_handle();
1747 }
1748 #endif
1749 
1750 
1751 /* class_get_declaredfields ****************************************************
1752 
1753  Return an array of declared fields of the given class.
1754 
1755  ARGUMENTS:
1756  c ............ class to get the fields of
1757  publicOnly ... show only public fields
1758 
1759  RETURN:
1760  array of java.lang.reflect.Field
1761 
1762 *******************************************************************************/
1763 
1764 #if defined(ENABLE_JAVASE)
1766 {
1767  /* Determine number of fields. */
1768 
1769  int count = 0;
1770 
1771  for (int32_t i = 0; i < c->fieldscount; i++)
1772  if ((c->fields[i].flags & ACC_PUBLIC) || (publicOnly == 0))
1773  count++;
1774 
1775  /* Create array of fields. */
1776 
1778 
1779  if (oa.is_null())
1780  return NULL;
1781 
1782  /* Get the fields and store them in the array. */
1783 
1784  for (int32_t i = 0, index = 0; i < c->fieldscount; i++) {
1785  fieldinfo* f = &(c->fields[i]);
1786 
1787  if ((f->flags & ACC_PUBLIC) || (publicOnly == 0)) {
1788  // Create a java.lang.reflect.Field object.
1789 
1791 
1792  /* Store object into array. */
1793 
1794  oa.set_element(index, rf.get_handle());
1795  index++;
1796  }
1797  }
1798 
1799  return oa.get_handle();
1800 }
1801 #endif
1802 
1803 
1804 /* class_get_declaredmethods ***************************************************
1805 
1806  Return an array of declared methods of the given class.
1807 
1808  ARGUMENTS:
1809  c ............ class to get the methods of
1810  publicOnly ... show only public methods
1811 
1812  RETURN:
1813  array of java.lang.reflect.Method
1814 
1815 *******************************************************************************/
1816 
1817 #if defined(ENABLE_JAVASE)
1819 {
1820  /* JOWENN: array classes do not declare methods according to mauve
1821  test. It should be considered, if we should return to my old
1822  clone method overriding instead of declaring it as a member
1823  function. */
1824 
1825  if (class_is_array(c)) {
1827  return oa.get_handle();
1828  }
1829 
1830  /* Determine number of methods. */
1831 
1832  int count = 0;
1833 
1834  for (int32_t i = 0; i < c->methodscount; i++) {
1835  methodinfo* m = &(c->methods[i]);
1836 
1837  if (((m->flags & ACC_PUBLIC) || (publicOnly == false)) &&
1838  ((m->name != utf8::init) && (m->name != utf8::clinit)) &&
1839  !(m->flags & ACC_MIRANDA))
1840  count++;
1841  }
1842 
1843  /* Create array of methods. */
1844 
1846 
1847  if (oa.is_null())
1848  return NULL;
1849 
1850  /* Get the methods and store them in the array. */
1851 
1852  for (int32_t i = 0, index = 0; i < c->methodscount; i++) {
1853  methodinfo* m = &(c->methods[i]);
1854 
1855  if (((m->flags & ACC_PUBLIC) || (publicOnly == false)) &&
1856  ((m->name != utf8::init) && (m->name != utf8::clinit)) &&
1857  !(m->flags & ACC_MIRANDA)) {
1858  // Create java.lang.reflect.Method object.
1859 
1861 
1862  /* Store object into array. */
1863 
1864  oa.set_element(index, rm.get_handle());
1865  index++;
1866  }
1867  }
1868 
1869  return oa.get_handle();
1870 }
1871 #endif
1872 
1873 
1874 /* class_get_declaringclass ****************************************************
1875 
1876  If the class or interface given is a member of another class,
1877  return the declaring class. For array and primitive classes return
1878  NULL.
1879 
1880 *******************************************************************************/
1881 
1883 {
1885  classinfo *dc;
1886 
1887  /* Get declaring class. */
1888 
1889  cr = c->declaringclass;
1890 
1891  if (cr.any == NULL)
1892  return NULL;
1893 
1894  /* Resolve the class if necessary. */
1895 
1896  if (cr.is_classref()) {
1897 /* dc = resolve_classref_eager(cr.ref); */
1898  dc = resolve_classref_or_classinfo_eager(cr, true);
1899 
1900  if (dc == NULL)
1901  return NULL;
1902 
1903  /* Store the resolved class in the class structure. */
1904 
1905  cr.cls = dc;
1906  }
1907 
1908  dc = cr.cls;
1909 
1910  return dc;
1911 }
1912 
1913 
1914 /* class_get_enclosingclass ****************************************************
1915 
1916  Return the enclosing class for the given class.
1917 
1918 *******************************************************************************/
1919 
1921 {
1923  classinfo *ec;
1924 
1925  /* Get enclosing class. */
1926 
1927  cr = c->enclosingclass;
1928 
1929  if (cr.any == NULL)
1930  return NULL;
1931 
1932  /* Resolve the class if necessary. */
1933 
1934  if (cr.is_classref()) {
1935 /* ec = resolve_classref_eager(cr.ref); */
1936  ec = resolve_classref_or_classinfo_eager(cr, true);
1937 
1938  if (ec == NULL)
1939  return NULL;
1940 
1941  /* Store the resolved class in the class structure. */
1942 
1943  cr.cls = ec;
1944  }
1945 
1946  ec = cr.cls;
1947 
1948  return ec;
1949 }
1950 
1951 
1952 /**
1953  * Return the enclosing constructor as java.lang.reflect.Constructor
1954  * object for the given class.
1955  *
1956  * @param c class to return the enclosing constructor for
1957  *
1958  * @return java.lang.reflect.Constructor object of the enclosing
1959  * constructor
1960  */
1961 #if defined(ENABLE_JAVASE)
1963 {
1965 
1966  if (m == NULL)
1967  return NULL;
1968 
1969  /* Check for <init>. */
1970 
1971  if (m->name != utf8::init)
1972  return NULL;
1973 
1974  // Create a java.lang.reflect.Constructor object.
1975 
1977 
1978  return rc.get_handle();
1979 }
1980 #endif
1981 
1982 
1983 /* class_get_enclosingmethod ***************************************************
1984 
1985  Return the enclosing method for the given class.
1986 
1987  IN:
1988  c ... class to return the enclosing method for
1989 
1990  RETURN:
1991  methodinfo of the enclosing method
1992 
1993 *******************************************************************************/
1994 
1996 {
1998  classinfo *ec;
1999  methodinfo *m;
2000 
2001  /* get enclosing class and method */
2002 
2003  ec = class_get_enclosingclass(c);
2004  cn = c->enclosingmethod;
2005 
2006  /* check for enclosing class and method */
2007 
2008  if (ec == NULL)
2009  return NULL;
2010 
2011  if (cn == NULL)
2012  return NULL;
2013 
2014  /* find method in enclosing class */
2015 
2016  m = class_findmethod(ec, cn->name, cn->descriptor);
2017 
2018  if (m == NULL) {
2019  exceptions_throw_internalerror("Enclosing method doesn't exist");
2020  return NULL;
2021  }
2022 
2023  return m;
2024 }
2025 
2026 
2027 /**
2028  * Return the enclosing method as java.lang.reflect.Method object for
2029  * the given class.
2030  *
2031  * @param c class to return the enclosing method for
2032  *
2033  * @return java.lang.reflect.Method object of the enclosing method
2034  */
2035 #if defined(ENABLE_JAVASE)
2037 {
2038  methodinfo* m;
2039 
2041 
2042  if (m == NULL)
2043  return NULL;
2044 
2045  /* check for <init> */
2046 
2047  if (m->name == utf8::init)
2048  return NULL;
2049 
2050  // Create a java.lang.reflect.Method object.
2051 
2053 
2054  return rm.get_handle();
2055 }
2056 #endif
2057 
2058 
2059 /* class_get_interfaces ********************************************************
2060 
2061  Return an array of interfaces of the given class.
2062 
2063 *******************************************************************************/
2064 
2066 {
2067  if (!(c->state & CLASS_LINKED))
2068  if (!link_class(c))
2069  return NULL;
2070 
2071  ClassArray interfaces(c->interfacescount);
2072 
2073  if (interfaces.is_null())
2074  return NULL;
2075 
2076  for (int32_t i = 0; i < c->interfacescount; i++) {
2077  classinfo* ic = c->interfaces[i];
2078 
2079  interfaces.set_element(i, ic);
2080  }
2081 
2082  return interfaces.get_handle();
2083 }
2084 
2085 
2086 /* class_get_annotations *******************************************************
2087 
2088  Get the unparsed declared annotations in a byte array
2089  of the given class.
2090 
2091  IN:
2092  c........the class of which the annotations should be returned
2093 
2094  RETURN VALUE:
2095  The unparsed declared annotations in a byte array
2096  (or NULL if there aren't any).
2097 
2098 *******************************************************************************/
2099 
2101 {
2102 #if defined(ENABLE_ANNOTATIONS)
2103  java_handle_t *annotations; /* unparsed annotations */
2104 
2105  LLNI_classinfo_field_get(c, annotations, annotations);
2106 
2107  return (java_handle_bytearray_t*) annotations;
2108 #else
2109  return NULL;
2110 #endif
2111 }
2112 
2113 
2114 /* class_get_modifiers *********************************************************
2115 
2116  Get the modifier flags of the given class.
2117 
2118  IN:
2119  c....the class of which the modifier flags should be returned
2120  ignoreInnerClassesAttrib
2121  RETURN VALUE:
2122  modifier flags
2123 
2124 *******************************************************************************/
2125 
2126 int32_t class_get_modifiers(classinfo *c, bool ignoreInnerClassesAttrib)
2127 {
2128  /* default to flags of passed class */
2129 
2130  int32_t flags = c->flags;
2131 
2132  /* if requested we check if passed class is inner class */
2133 
2134  if (!ignoreInnerClassesAttrib && (c->innerclasscount != 0)) {
2135  /* search for passed class as inner class */
2136 
2137  for (int i = 0; i < c->innerclasscount; i++) {
2140 
2141  /* Check if inner is a classref or a real class and get
2142  the name of the structure */
2143 
2144  Utf8String innername = CLASSREF_OR_CLASSINFO_NAME(inner);
2145 
2146  /* innerclass is this class */
2147 
2148  if (innername == c->name) {
2149  /* has the class actually an outer class? */
2150 
2151  if (outer.any)
2152  /* return flags got from the outer class file */
2153  flags = c->innerclass[i].flags;
2154 
2155  break;
2156  }
2157  }
2158  }
2159 
2160  /* remove ACC_SUPER bit from flags */
2161 
2162  return flags & ~ACC_SUPER & ACC_CLASS_REFLECT_MASK;
2163 }
2164 
2165 
2166 /**
2167  * Helper function for the function class_is_or_almost_initialized.
2168  */
2170 {
2172  return t == c->initializing_thread;
2173 }
2174 
2175 /* class_get_signature *********************************************************
2176 
2177  Return the signature of the given class. For array and primitive
2178  classes return NULL.
2179 
2180 *******************************************************************************/
2181 
2182 #if defined(ENABLE_JAVASE)
2184 {
2185  /* For array and primitive classes return NULL. */
2186 
2187  if (class_is_array(c) || class_is_primitive(c))
2188  return NULL;
2189 
2190  return c->signature;
2191 }
2192 #endif
2193 
2194 
2195 /* class_printflags ************************************************************
2196 
2197  Prints flags of a class.
2198 
2199 *******************************************************************************/
2200 
2201 #if !defined(NDEBUG)
2203 {
2204  if (c == NULL) {
2205  printf("NULL");
2206  return;
2207  }
2208 
2209  if (c->flags & ACC_PUBLIC) printf(" PUBLIC");
2210  if (c->flags & ACC_PRIVATE) printf(" PRIVATE");
2211  if (c->flags & ACC_PROTECTED) printf(" PROTECTED");
2212  if (c->flags & ACC_STATIC) printf(" STATIC");
2213  if (c->flags & ACC_FINAL) printf(" FINAL");
2214  if (c->flags & ACC_SYNCHRONIZED) printf(" SYNCHRONIZED");
2215  if (c->flags & ACC_VOLATILE) printf(" VOLATILE");
2216  if (c->flags & ACC_TRANSIENT) printf(" TRANSIENT");
2217  if (c->flags & ACC_NATIVE) printf(" NATIVE");
2218  if (c->flags & ACC_INTERFACE) printf(" INTERFACE");
2219  if (c->flags & ACC_ABSTRACT) printf(" ABSTRACT");
2220 }
2221 #endif
2222 
2223 
2224 /* class_print *****************************************************************
2225 
2226  Prints classname plus flags.
2227 
2228 *******************************************************************************/
2229 
2230 #if !defined(NDEBUG)
2232 {
2233  if (c == NULL) {
2234  printf("NULL");
2235  return;
2236  }
2237 
2239  class_printflags(c);
2240 }
2241 #endif
2242 
2243 
2244 /* class_classref_print ********************************************************
2245 
2246  Prints classname plus referer class.
2247 
2248 *******************************************************************************/
2249 
2250 #if !defined(NDEBUG)
2252 {
2253  if (cr == NULL) {
2254  printf("NULL");
2255  return;
2256  }
2257 
2259  printf("(ref.by ");
2260  if (cr->referer)
2261  class_print(cr->referer);
2262  else
2263  printf("NULL");
2264  printf(")");
2265 }
2266 #endif
2267 
2268 
2269 /* class_println ***************************************************************
2270 
2271  Prints classname plus flags and new line.
2272 
2273 *******************************************************************************/
2274 
2275 #if !defined(NDEBUG)
2277 {
2278  class_print(c);
2279  printf("\n");
2280 }
2281 #endif
2282 
2283 
2284 /* class_classref_println ******************************************************
2285 
2286  Prints classname plus referer class and new line.
2287 
2288 *******************************************************************************/
2289 
2290 #if !defined(NDEBUG)
2292 {
2294  printf("\n");
2295 }
2296 #endif
2297 
2298 
2299 /* class_classref_or_classinfo_print *******************************************
2300 
2301  Prints classname plus referer class.
2302 
2303 *******************************************************************************/
2304 
2305 #if !defined(NDEBUG)
2307 {
2308  if (c.any == NULL) {
2309  printf("(classref_or_classinfo) NULL");
2310  return;
2311  }
2312  if (c.is_classref())
2314  else
2315  class_print(c.cls);
2316 }
2317 #endif
2318 
2319 
2320 /* class_classref_or_classinfo_println *****************************************
2321 
2322  Prints classname plus referer class and a newline.
2323 
2324 *******************************************************************************/
2325 
2326 #if !defined(NDEBUG)
2328 {
2330  printf("\n");
2331 }
2332 #endif
2333 
2334 
2335 /* class_showconstantpool ******************************************************
2336 
2337  Dump the constant pool of the given class to stdout.
2338 
2339 *******************************************************************************/
2340 
2341 #if !defined(NDEBUG)
2343 {
2344  printf ("---- dump of constant pool ----\n");
2345 
2346  for (int32_t i=0; i<c->cpcount; i++) {
2347  printf ("#%u: ", i);
2348 
2349  if (void *e = c->cpinfos[i]) {
2350  switch ((ConstantPoolTag) c->cptags[i]) {
2351  case CONSTANT_Class:
2352  printf ("Classreference -> ");
2354  break;
2355  case CONSTANT_Fieldref:
2356  printf ("Fieldref -> ");
2358  break;
2359  case CONSTANT_Methodref:
2360  printf ("Methodref -> ");
2362  break;
2364  printf ("InterfaceMethod -> ");
2366  break;
2367  case CONSTANT_String:
2368  printf ("String -> ");
2369  utf_display_printable_ascii ((utf*) e);
2370  break;
2371  case CONSTANT_Integer:
2372  printf ("Integer -> %d", *reinterpret_cast<int32_t*>(e));
2373  break;
2374  case CONSTANT_Float:
2375  printf ("Float -> %f", *reinterpret_cast<float*>(e));
2376  break;
2377  case CONSTANT_Double:
2378  printf ("Double -> %f", *reinterpret_cast<double*>(e));
2379  break;
2380  case CONSTANT_Long:
2381  printf ("Long -> %" PRId64, *reinterpret_cast<int64_t*>(e));
2382  break;
2383  case CONSTANT_NameAndType:
2384  {
2386  printf ("NameAndType: ");
2388  printf (" ");
2390  }
2391  break;
2392  case CONSTANT_Utf8:
2393  printf ("Utf8 -> ");
2394  utf_display_printable_ascii ((utf*) e);
2395  break;
2396  case CONSTANT_MethodType: {
2398 
2399  printf ("MethodType -> ");
2401  break;
2402  }
2403  case CONSTANT_MethodHandle: {
2405 
2406  printf ("MethodHandle -> ");
2409  break;
2410  }
2411  case CONSTANT_InvokeDynamic: {
2413 
2414  printf ("InvokeDynamic -> ");
2417  printf(" [%u]", indy->bootstrap_method_index);
2418  break;
2419  }
2420  default:
2421  log_text("Invalid type of ConstantPool-Entry");
2422  assert(0);
2423  }
2424  }
2425 
2426  printf ("\n");
2427  }
2428 }
2429 #endif /* !defined(NDEBUG) */
2430 
2431 
2432 /* class_showmethods ***********************************************************
2433 
2434  Dump info about the fields and methods of the given class to stdout.
2435 
2436 *******************************************************************************/
2437 
2438 #if !defined(NDEBUG)
2440 {
2441  printf("--------- Fields and Methods ----------------\n");
2442  printf("Flags: ");
2443  class_printflags(c);
2444  printf("\n");
2445 
2446  printf("This: ");
2448  printf("\n");
2449 
2450  if (c->super) {
2451  printf("Super: ");
2453  printf ("\n");
2454  }
2455 
2456  printf("Index: %d\n", c->index);
2457 
2458  printf("Interfaces:\n");
2459  for (int32_t i = 0; i < c->interfacescount; i++) {
2460  printf(" ");
2462  printf (" (%d)\n", c->interfaces[i]->index);
2463  }
2464 
2465  printf("Fields:\n");
2466  for (int32_t i = 0; i < c->fieldscount; i++)
2467  field_println(&(c->fields[i]));
2468 
2469  printf("Methods:\n");
2470  for (int32_t i = 0; i < c->methodscount; i++) {
2471  methodinfo *m = &(c->methods[i]);
2472 
2473  if (!(m->flags & ACC_STATIC))
2474  printf("vftblindex: %d ", m->vftblindex);
2475 
2476  method_println(m);
2477  }
2478 
2479  printf ("Virtual function table:\n");
2480  for (int32_t i = 0; i < c->vftbl->vftbllength; i++)
2481  printf ("entry: %d, %ld\n", i, (long int) (c->vftbl->table[i]));
2482 }
2483 #endif /* !defined(NDEBUG) */
2484 
2485 namespace cacao {
2486 
2488  if (c == NULL) {
2489  os << "NULL";
2490  return os;
2491  }
2492 
2493  os << (Utf8String)c->name;
2494  // print flags
2495  if (c->flags & ACC_PUBLIC) os << " PUBLIC";
2496  if (c->flags & ACC_PRIVATE) os << " PRIVATE";
2497  if (c->flags & ACC_PROTECTED) os << " PROTECTED";
2498  if (c->flags & ACC_STATIC) os << " STATIC";
2499  if (c->flags & ACC_FINAL) os << " FINAL";
2500  if (c->flags & ACC_SYNCHRONIZED) os << " SYNCHRONIZED";
2501  if (c->flags & ACC_VOLATILE) os << " VOLATILE";
2502  if (c->flags & ACC_TRANSIENT) os << " TRANSIENT";
2503  if (c->flags & ACC_NATIVE) os << " NATIVE";
2504  if (c->flags & ACC_INTERFACE) os << " INTERFACE";
2505  if (c->flags & ACC_ABSTRACT) os << " ABSTRACT";
2506 
2507  return os;
2508 }
2509 
2510 }
2511 
2512 /*
2513  * These are local overrides for various environment variables in Emacs.
2514  * Please do not remove this and leave it at the end of the file, where
2515  * Emacs will automagically detect them.
2516  * ---------------------------------------------------------------------
2517  * Local variables:
2518  * mode: c++
2519  * indent-tabs-mode: t
2520  * c-basic-offset: 4
2521  * tab-width: 4
2522  * End:
2523  * vim:noexpandtab:sw=4:ts=4:
2524  */
methodptr * interfacetable[1]
Definition: vftbl.hpp:99
java_handle_objectarray_t * class_get_declaredfields(classinfo *c, bool publicOnly)
Definition: class.cpp:1765
A MethodType constant stored in the constant pool.
Definition: references.hpp:140
classref_or_classinfo outer_class
Definition: class.hpp:166
bool builtin_instanceof(java_handle_t *o, classinfo *c)
Definition: builtin.cpp:403
Utf8String name
Definition: method.hpp:71
java_object_t header
Definition: class.hpp:73
jlong jlong jlong jlong jint jmethodID jint slot
Definition: jvmti.h:497
constant_FMIref *const fmi
Definition: references.hpp:131
std::size_t index
classinfo * classcache_lookup_defined_or_initiated(classloader_t *loader, Utf8String classname)
Definition: classcache.cpp:662
dummy_java_lang_Class object
Definition: class.hpp:88
ConstantPoolTag
Types for entries of a classes constant pool.
Definition: global.hpp:162
void method_free(methodinfo *m)
Definition: method.cpp:608
classinfo * class_java_lang_reflect_Field
Definition: globals.cpp:82
Utf8String substring(size_t from) const
Definition: utf8.cpp:378
Utf8String name
Definition: field.hpp:61
static void class_freecpool(classinfo *c)
Definition: class.cpp:608
#define STATISTICS(x)
Wrapper for statistics only code.
Definition: statistics.hpp:975
fieldinfo * class_resolvefield(classinfo *c, Utf8String name, Utf8String desc, classinfo *referer)
Definition: class.cpp:1383
constant_classref * class_get_classref_component_of(constant_classref *ref)
Definition: class.cpp:1094
classinfo * load_class_from_classbuffer(ClassBuffer &cb)
Definition: loader.cpp:2021
methodinfo * class_resolveclassmethod(classinfo *c, Utf8String name, Utf8String desc, classinfo *referer, bool throwexception)
Definition: class.cpp:1211
official tags from JVM spec
Definition: global.hpp:164
virtual java_handle_t * get_handle() const
void * class_getconstant(classinfo *c, u4 pos, ConstantPoolTag ctype)
Definition: class.cpp:679
classinfo * classcache_lookup(classloader_t *initloader, Utf8String classname)
Definition: classcache.cpp:564
Definition: os.hpp:123
classinfo * load_newly_created_array(classinfo *c, classloader_t *loader)
Definition: loader.cpp:2094
void exceptions_throw_linkageerror(const char *message, classinfo *c)
Definition: exceptions.cpp:833
methodinfo * methods
Definition: class.hpp:113
java_handle_t * class_get_enclosingconstructor(classinfo *c)
Return the enclosing constructor as java.lang.reflect.Constructor object for the given class...
Definition: class.cpp:1962
static classinfo * get_class_by_type(int type)
Returns the primitive class of the given type.
Definition: primitive.cpp:253
argument_type from
methodinfo * class_get_enclosingmethod_raw(classinfo *c)
Definition: class.cpp:1995
virtual java_handle_array_t * get_handle() const
Definition: array.hpp:103
void exceptions_throw_nosuchmethoderror(classinfo *c, Utf8String name, Utf8String desc)
Definition: exceptions.cpp:889
bool is_classref() const
Definition: references.hpp:66
static Utf8String from_utf8_slash_to_dot(const char *, size_t)
Definition: utf8.cpp:343
classinfo * super
Definition: class.hpp:102
Utf8String packagename
Definition: class.hpp:132
byte_iterator end() const
Definition: utf8.hpp:107
void class_print(classinfo *c)
Definition: class.cpp:2231
size_t size() const
Definition: utf8.hpp:161
void init()
Definition: lockword.hpp:61
An invokedynamic call site.
Definition: references.hpp:154
classcache_class_entry * next
Definition: classcache.hpp:103
int32_t class_get_modifiers(classinfo *c, bool ignoreInnerClassesAttrib)
Definition: class.cpp:2126
classinfo * class_array_of(classinfo *component, bool link)
Definition: class.cpp:832
uintptr_t lockword
Definition: global.hpp:265
s4 state
Definition: class.hpp:115
u1 * cptags
Definition: class.hpp:95
static fieldinfo * class_resolvefield_int(classinfo *c, Utf8String name, Utf8String desc)
Definition: class.cpp:1344
Utf8String class_get_signature(classinfo *c)
Definition: class.cpp:2183
void * innerclass_getconstant(classinfo *c, u4 pos, ConstantPoolTag ctype)
Definition: class.cpp:708
classinfo * class_get_declaringclass(classinfo *c)
Definition: class.cpp:1882
classloader_t * classloader
Definition: class.hpp:151
Actual implementation of access class for Java Object arrays.
Definition: array.hpp:381
void exceptions_throw_nosuchfielderror(classinfo *c, Utf8String name)
Definition: exceptions.cpp:863
void class_classref_or_classinfo_print(classref_or_classinfo c)
Definition: class.cpp:2306
static bool class_load_attribute_enclosingmethod(ClassBuffer &cb)
Definition: class.cpp:391
s4 classrefcount
Definition: class.hpp:98
bool initverbose
Definition: options.cpp:71
GNU Classpath java/lang/reflect/Field.
void field_println(fieldinfo *f)
Definition: field.cpp:508
hashtable hashtable_classcache
Definition: classcache.cpp:223
classref_or_classinfo enclosingclass
Definition: class.hpp:129
int32_t interfacescount
Definition: class.hpp:106
void class_classref_println(constant_classref *cr)
Definition: class.cpp:2291
classinfo * classcache_store(classloader_t *initloader, classinfo *cls, bool mayfree)
Definition: classcache.cpp:730
#define FREE(ptr, type)
Definition: memory.hpp:94
vftbl_t * componentvftbl
Definition: array.hpp:73
bool class_is_instance(classinfo *c, java_handle_t *h)
Definition: class.cpp:1572
constant_classref * ref
Definition: references.hpp:62
void exceptions_throw_classformaterror(classinfo *c, const char *message,...)
Definition: exceptions.cpp:634
uint8_t u1
Definition: types.hpp:40
u1 * methodptr
Definition: global.hpp:40
classinfo * class_get_enclosingclass(classinfo *c)
Definition: class.cpp:1920
classinfo * pseudo_class_Arraystub
Definition: globals.cpp:106
static bool class_is_array(classinfo *c)
Definition: class.hpp:341
JNIEnv jclass jobject const char * name
Definition: jvmti.h:312
void field_fieldref_print(constant_FMIref *fr)
Definition: field.cpp:522
void set_element(int32_t index, T value)
Definition: array.hpp:255
classinfo * class_java_lang_Object
Definition: globals.cpp:28
const Utf8String name
Definition: references.hpp:103
constant_classref * classrefs
Definition: class.hpp:99
static bool class_load_attribute_sourcefile(ClassBuffer &cb)
Definition: class.cpp:336
methodinfo * class_findmethod(classinfo *c, Utf8String name, Utf8String desc)
Definition: class.cpp:1124
bool class_is_arraycompatible(arraydescriptor *desc, arraydescriptor *target)
Definition: class.cpp:1488
classinfo * class_multiarray_of(s4 dim, classinfo *element, bool link)
Definition: class.cpp:881
void class_set_packagename(classinfo *c)
Definition: class.cpp:102
bool loader_skip_attribute_body(ClassBuffer &cb)
Definition: loader.cpp:499
constant_nameandtype * enclosingmethod
Definition: class.hpp:130
GNU Classpath java/lang/reflect/Constructor.
const uint16_t bootstrap_method_index
Definition: references.hpp:158
#define UNLOCK_CLASSRENUMBER_LOCK
Definition: linker.hpp:52
int32_t fieldscount
Definition: class.hpp:109
#define MCOPY(dest, src, type, num)
Definition: memory.hpp:103
const Utf8String name
Definition: references.hpp:159
void link(basicblock *v, basicblock *w)
Definition: dominator.cpp:178
java_handle_objectarray_t * class_get_declaredconstructors(classinfo *c, bool publicOnly)
Return an array of declared constructors of the given class.
Definition: class.cpp:1708
java_handle_t * class_get_classname(classinfo *c)
Returns the classname of the class, where slashes (&#39;/&#39;) are replaced by dots (&#39;.
Definition: class.cpp:86
#define LLNI_classinfo_wrap(classinfo)
Definition: llni.hpp:110
fieldinfo * fields
Definition: class.hpp:110
fieldinfo * class_findfield_by_name(classinfo *c, Utf8String name, bool throwexception)
Definition: class.cpp:1319
void * heap_alloc_uncollectable(u4 size)
Definition: heap.c:345
s4 interfacetablelength
Definition: vftbl.hpp:103
Utf8String descriptor
Definition: field.hpp:62
bool class_load_attributes(ClassBuffer &cb)
Definition: class.cpp:456
Utf8String descriptor
Definition: method.hpp:72
uint16_t read_u2()
Definition: suck.hpp:150
java_handle_objectarray_t * class_get_declaredclasses(classinfo *c, bool publicOnly)
Definition: class.cpp:1626
constant_classref * class_lookup_classref(classinfo *cls, Utf8String name)
Definition: class.cpp:941
threadobject * initializing_thread
Definition: class.hpp:120
s4 vftblindex
Definition: method.hpp:81
#define MFREE(ptr, type, num)
Definition: memory.hpp:97
classcache_class_entry * classes
Definition: classcache.hpp:95
java_handle_objectarray_t * class_get_interfaces(classinfo *c)
Definition: class.cpp:2065
void exceptions_throw_incompatibleclasschangeerror(classinfo *c, const char *message)
Definition: exceptions.cpp:769
java_handle_bytearray_t * class_get_annotations(classinfo *c)
Definition: class.cpp:2100
constant_classref * class_get_self_classref(classinfo *cls)
Definition: class.cpp:1013
void mem_free(void *m, int32_t size)
Definition: memory.cpp:141
uint16_t u2
Definition: types.hpp:43
internally used tags
Definition: global.hpp:180
void method_println(methodinfo *m)
Definition: method.cpp:1218
java_handle_t * class_get_enclosingmethod(classinfo *c)
Return the enclosing method as java.lang.reflect.Method object for the given class.
Definition: class.cpp:2036
bool class_initializing_thread_is_self(classinfo *c)
Helper function for the function class_is_or_almost_initialized.
Definition: class.cpp:2169
s4 vftbllength
Definition: vftbl.hpp:102
java_handle_objectarray_t * class_get_declaredmethods(classinfo *c, bool publicOnly)
Definition: class.cpp:1818
void field_free(fieldinfo *f)
Definition: field.cpp:390
This file contains the statistics framework.
Utf8String name
Definition: class.hpp:91
classinfo * clazz
Definition: vftbl.hpp:100
s4 baseval
Definition: vftbl.hpp:104
void class_println(classinfo *c)
Definition: class.cpp:2276
s4 flags
Definition: field.hpp:59
classinfo * class_java_lang_Class
Definition: globals.cpp:35
methodinfo * class_resolvemethod(classinfo *c, Utf8String name, Utf8String desc)
Definition: class.cpp:1145
u2 innerclasscount
Definition: class.hpp:125
void exceptions_throw_abstractmethoderror(void)
Definition: exceptions.cpp:602
void class_showconstantpool(classinfo *c)
Definition: class.cpp:2342
GNU Classpath java/lang/reflect/Method.
fieldinfo * class_findfield(classinfo *c, Utf8String name, Utf8String desc)
Definition: class.cpp:1299
Simple stream class for formatted output.
Definition: OStream.hpp:141
void class_classref_print(constant_classref *cr)
Definition: class.cpp:2251
void exceptions_throw_internalerror(const char *message,...)
Definition: exceptions.cpp:805
classinfo * class_java_lang_reflect_Method
Definition: globals.cpp:83
const Utf8String name
Definition: loader.hpp:83
void ** ptr
Definition: hashtable.hpp:781
s4 flags
Definition: class.hpp:90
void class_printflags(classinfo *c)
Definition: class.cpp:2202
classref_or_classinfo inner_class
Definition: class.hpp:165
const Utf8String descriptor
Definition: references.hpp:160
static Utf8String from_utf8(const char *, size_t)
Definition: utf8.cpp:335
jlong tag
Definition: jvmti.h:395
MIIterator i
constant_classref * class_get_classref(classinfo *cls, Utf8String name)
Definition: class.cpp:985
Fieldref, Methodref and InterfaceMethodref.
Definition: references.hpp:86
#define GCNEW_UNCOLLECTABLE(type, num)
Definition: memory.hpp:115
int32_t s4
Definition: types.hpp:45
MIIterator pos
bool class_isanysubclass(classinfo *sub, classinfo *super)
Definition: class.cpp:1435
#define LLNI_classinfo_field_get(cls, field, variable)
Definition: llni.hpp:82
s4 cpcount
Definition: class.hpp:94
bool builtin_arrayinstanceof(java_handle_t *h, classinfo *targetclass)
Definition: builtin.cpp:494
s4 index
Definition: class.hpp:116
extra_classref * next
Definition: class.hpp:182
#define CLASSREF_OR_CLASSINFO_NAME(value)
Definition: references.hpp:194
const Utf8String descriptor
Definition: references.hpp:104
Utf8String sourcefile
Definition: class.hpp:133
bool loader_load_attribute_signature(ClassBuffer &cb, Utf8String &signature)
Definition: loader.cpp:960
bool class_issubclass(classinfo *sub, classinfo *super)
Definition: class.cpp:1404
int32_t methodscount
Definition: class.hpp:112
OStream & operator<<(OStream &OS, const std::string &t)
Definition: OStream.hpp:459
classinfo ** interfaces
Definition: class.hpp:107
arraydescriptor * arraydesc
Definition: vftbl.hpp:101
#define MNEW(type, num)
Definition: memory.hpp:96
uint32_t read_u4()
Definition: suck.hpp:155
void utf_display_printable_ascii(Utf8String u)
Definition: utf8.cpp:532
MIIterator e
void class_classref_or_classinfo_println(classref_or_classinfo c)
Definition: class.cpp:2327
static JavaString from_utf8_slash_to_dot(Utf8String)
Definition: string.cpp:202
uint32_t u4
Definition: types.hpp:46
#define LOCK_CLASSRENUMBER_LOCK
Definition: linker.hpp:51
const Utf8String descriptor
Definition: references.hpp:144
vftbl_t * elementvftbl
Definition: array.hpp:74
Lockword.
Definition: lockword.hpp:37
void loadingtime_stop(void)
Definition: statistics.cpp:65
vftbl_t * vftbl
Definition: class.hpp:121
classinfo * get_class() const
Definition: suck.hpp:117
byte_iterator begin() const
Definition: utf8.hpp:106
bool annotation_load_class_attribute_runtimevisibleannotations(ClassBuffer &cb)
Definition: annotation.cpp:412
static threadobject * thread_get_current()
Return the threadobject for the current thread.
Definition: thread-none.hpp:56
void class_showmethods(classinfo *c)
Definition: class.cpp:2439
void class_free(classinfo *c)
Definition: class.cpp:739
void method_methodref_print(constant_FMIref *mr)
Definition: method.cpp:1235
Definition: classcache.hpp:98
classinfo * link_class(classinfo *c)
Definition: linker.cpp:378
#define STAT_DECLARE_GROUP(var)
Declare an external group (or subgroup).
Definition: statistics.hpp:970
ArrayType arraytype
Definition: array.hpp:75
static methodinfo * class_resolveinterfacemethod_intern(classinfo *c, Utf8String name, Utf8String desc)
Definition: class.cpp:1176
Utf8String signature
Definition: class.hpp:135
void class_postset_header_vftbl(void)
Definition: class.cpp:210
java_handle_t * exceptions_get_exception(void)
Definition: exceptions.cpp:76
classinfo *const referer
Definition: references.hpp:47
bool class_is_assignable_from(classinfo *to, classinfo *from)
Definition: class.cpp:1539
void ** cpinfos
Definition: class.hpp:96
extra_classref * extclassrefs
Definition: class.hpp:100
classref_or_classinfo declaringclass
Definition: class.hpp:128
bool check_size(size_t sz)
Assert that at least &lt;sz&gt; bytes are left to read.
Definition: suck.hpp:135
BeginInst * target
static classinfo * get_array_class(Utf8String name, classloader_t *initloader, classloader_t *defloader, bool link)
Definition: class.cpp:793
methodptr table[1]
Definition: vftbl.hpp:116
static bool class_is_primitive(classinfo *c)
Definition: class.hpp:311
classcache_name_entry * hashlink
Definition: classcache.hpp:94
classinfo * class_create_classinfo(Utf8String classname)
Definition: class.cpp:145
s4 flags
Definition: method.hpp:70
constant_classref classref
Definition: class.hpp:183
s4 diffval
Definition: vftbl.hpp:106
classinfo * resolve_classref_or_classinfo_eager(classref_or_classinfo cls, bool checkaccess)
Definition: resolve.cpp:437
bool is_null() const
Definition: array.hpp:203
GNU Classpath java/lang/Class.
classinfo * class_java_lang_reflect_Constructor
Definition: globals.cpp:81
innerclassinfo * innerclass
Definition: class.hpp:126
classinfo * classcache_lookup_defined(classloader_t *defloader, Utf8String classname)
Definition: classcache.cpp:616
vftbl_t * vftbl
Definition: global.hpp:264
#define log_text(s)
Definition: logging.hpp:170
#define STAT_DECLARE_VAR(type, var, init)
Declare an external statistics variable.
Definition: statistics.hpp:963
void log_message_utf(const char *msg, Utf8String u)
Definition: logging.cpp:214
Actual implementation of access class for java.lang.Class arrays.
Definition: array.hpp:391
const Utf8String descriptor
Definition: loader.hpp:84
classinfo * classobj
Definition: classcache.hpp:100
const char const void jint length
Definition: jvmti.h:352
const Utf8String name
Definition: references.hpp:48
Definition: classcache.hpp:91
#define printf(...)
Definition: ssa2.cpp:40
classinfo * class_define(Utf8String name, classloader_t *cl, int32_t length, uint8_t *data, java_handle_t *pd)
Definition: class.cpp:243
bool annotation_load_class_attribute_runtimeinvisibleannotations(ClassBuffer &cb)
Definition: annotation.cpp:439
classinfo * class_get_componenttype(classinfo *c)
Definition: class.cpp:1594
constant_classref * class_get_classref_multiarray_of(s4 dim, constant_classref *ref)
Definition: class.cpp:1038
void loadingtime_start(void)
Definition: statistics.cpp:49
Utf8String name
Definition: class.hpp:167
methodinfo * class_resolveinterfacemethod(classinfo *c, Utf8String name, Utf8String desc, classinfo *referer, bool throwexception)
Definition: class.cpp:1261