1 /* Functions related to building classes and their related objects.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 Java and all Java-based marks are trademarks or registered trademarks
23 of Sun Microsystems, Inc. in the United States and other countries.
24 The Free Software Foundation is independent of Sun Microsystems, Inc. */
26 /* Written by Per Bothner <bothner@cygnus.com> */
30 #include "coretypes.h"
35 #include "java-tree.h"
46 /* DOS brain-damage */
48 #define O_BINARY 0 /* MS-DOS brain-damage */
51 static tree make_method_value (tree);
52 static tree build_java_method_type (tree, tree, int);
53 static int32 hashUtf8String (const char *, int);
54 static tree make_field_value (tree);
55 static tree get_dispatch_vector (tree);
56 static tree get_dispatch_table (tree, tree);
57 static int supers_all_compiled (tree type);
58 static void add_interface_do (tree, tree, int);
59 static tree maybe_layout_super_class (tree, tree);
60 static int assume_compiled (const char *);
61 static tree build_method_symbols_entry (tree);
63 static GTY(()) rtx registerClass_libfunc;
65 struct obstack temporary_obstack;
67 /* The compiler generates different code depending on whether or not
68 it can assume certain classes have been compiled down to native
69 code or not. The compiler options -fassume-compiled= and
70 -fno-assume-compiled= are used to create a tree of
71 assume_compiled_node objects. This tree is queried to determine if
72 a class is assume to be compiled or not. Each node in the tree
73 represents either a package or a specific class. */
75 typedef struct assume_compiled_node_struct
77 /* The class or package name. */
80 /* Nonzero if this represents an exclusion. */
83 /* Pointers to other nodes in the tree. */
84 struct assume_compiled_node_struct *parent;
85 struct assume_compiled_node_struct *sibling;
86 struct assume_compiled_node_struct *child;
87 } assume_compiled_node;
89 static assume_compiled_node *find_assume_compiled_node (assume_compiled_node *,
92 /* This is the root of the include/exclude tree. */
94 static assume_compiled_node *assume_compiled_tree;
96 static GTY(()) tree class_roots[5];
97 #define registered_class class_roots[0]
98 #define fields_ident class_roots[1] /* get_identifier ("fields") */
99 #define info_ident class_roots[2] /* get_identifier ("info") */
100 #define class_list class_roots[3]
101 #define class_dtable_decl class_roots[4]
103 /* Return the node that most closely represents the class whose name
104 is IDENT. Start the search from NODE. Return NULL if an
105 appropriate node does not exist. */
107 static assume_compiled_node *
108 find_assume_compiled_node (assume_compiled_node *node, const char *ident)
112 size_t node_ident_length = strlen (node->ident);
114 /* node_ident_length is zero at the root of the tree. If the
115 identifiers are the same length, then we have matching
116 classes. Otherwise check if we've matched an enclosing
119 if (node_ident_length == 0
120 || (strncmp (ident, node->ident, node_ident_length) == 0
121 && (strlen (ident) == node_ident_length
122 || ident[node_ident_length] == '.')))
124 /* We've found a match, however, there might be a more
127 assume_compiled_node *found = find_assume_compiled_node (node->child,
135 /* No match yet. Continue through the sibling list. */
136 node = node->sibling;
139 /* No match at all in this tree. */
143 /* Add a new IDENT to the include/exclude tree. It's an exclusion
144 if EXCLUDEP is nonzero. */
147 add_assume_compiled (const char *ident, int excludep)
150 assume_compiled_node *parent;
151 assume_compiled_node *node =
152 xmalloc (sizeof (assume_compiled_node));
154 node->ident = xstrdup (ident);
155 node->excludep = excludep;
158 /* Create the root of the tree if it doesn't exist yet. */
160 if (NULL == assume_compiled_tree)
162 assume_compiled_tree = xmalloc (sizeof (assume_compiled_node));
163 assume_compiled_tree->ident = "";
164 assume_compiled_tree->excludep = 0;
165 assume_compiled_tree->sibling = NULL;
166 assume_compiled_tree->child = NULL;
167 assume_compiled_tree->parent = NULL;
170 /* Calling the function with the empty string means we're setting
171 excludep for the root of the hierarchy. */
175 assume_compiled_tree->excludep = excludep;
179 /* Find the parent node for this new node. PARENT will either be a
180 class or a package name. Adjust PARENT accordingly. */
182 parent = find_assume_compiled_node (assume_compiled_tree, ident);
183 len = strlen (parent->ident);
184 if (parent->ident[len] && parent->ident[len] != '.')
185 parent = parent->parent;
187 /* Insert NODE into the tree. */
189 node->parent = parent;
190 node->sibling = parent->child;
191 parent->child = node;
194 /* Returns nonzero if IDENT is the name of a class that the compiler
195 should assume has been compiled to object code. */
198 assume_compiled (const char *ident)
200 assume_compiled_node *i;
203 if (NULL == assume_compiled_tree)
206 i = find_assume_compiled_node (assume_compiled_tree,
209 result = ! i->excludep;
214 /* Return an IDENTIFIER_NODE the same as (OLD_NAME, OLD_LENGTH).
215 except that characters matching OLD_CHAR are substituted by NEW_CHAR.
216 Also, PREFIX is prepended, and SUFFIX is appended. */
219 ident_subst (const char* old_name,
226 int prefix_len = strlen (prefix);
227 int suffix_len = strlen (suffix);
228 int i = prefix_len + old_length + suffix_len + 1;
232 char *buffer = alloca (i);
234 strcpy (buffer, prefix);
235 for (i = 0; i < old_length; i++)
237 char ch = old_name[i];
240 buffer[prefix_len + i] = ch;
242 strcpy (buffer + prefix_len + old_length, suffix);
243 return get_identifier (buffer);
246 /* Return an IDENTIFIER_NODE the same as OLD_ID,
247 except that characters matching OLD_CHAR are substituted by NEW_CHAR.
248 Also, PREFIX is prepended, and SUFFIX is appended. */
251 identifier_subst (const tree old_id,
257 return ident_subst (IDENTIFIER_POINTER (old_id), IDENTIFIER_LENGTH (old_id),
258 prefix, old_char, new_char, suffix);
261 /* Generate a valid C identifier from the name of the class TYPE,
262 prefixed by PREFIX. */
265 mangled_classname (const char *prefix, tree type)
267 tree ident = TYPE_NAME (type);
268 if (TREE_CODE (ident) != IDENTIFIER_NODE)
269 ident = DECL_NAME (ident);
270 return identifier_subst (ident, prefix, '.', '_', "");
277 type = make_node (RECORD_TYPE);
278 TYPE_BINFO (type) = make_tree_vec (BINFO_ELTS);
279 MAYBE_CREATE_TYPE_TYPE_LANG_SPECIFIC (type);
284 /* Given a fully-qualified classname in NAME (whose length is NAME_LENGTH),
285 and where each of the constituents is separated by '/',
286 return a corresponding IDENTIFIER_NODE, except using '.' as separator. */
289 unmangle_classname (const char *name, int name_length)
291 tree to_return = ident_subst (name, name_length, "", '/', '.', "");
292 /* It's not sufficient to compare to_return and get_identifier
293 (name) to determine whether to_return is qualified. There are
294 cases in signature analysis where name will be stripped of a
296 name = IDENTIFIER_POINTER (to_return);
300 QUALIFIED_P (to_return) = 1;
308 push_class (tree class_type, tree class_name)
310 tree decl, signature;
311 const char *save_input_filename = input_filename;
312 int save_lineno = lineno;
313 tree source_name = identifier_subst (class_name, "", '.', '/', ".java");
314 CLASS_P (class_type) = 1;
315 input_filename = IDENTIFIER_POINTER (source_name);
317 decl = build_decl (TYPE_DECL, class_name, class_type);
319 /* dbxout needs a DECL_SIZE if in gstabs mode */
320 DECL_SIZE (decl) = integer_zero_node;
322 input_filename = save_input_filename;
323 lineno = save_lineno;
324 signature = identifier_subst (class_name, "L", '.', '/', ";");
325 IDENTIFIER_SIGNATURE_TYPE (signature) = build_pointer_type (class_type);
327 /* Setting DECL_ARTIFICIAL forces dbxout.c to specific the type is
328 both a typedef and in the struct name-space. We may want to re-visit
329 this later, but for now it reduces the changes needed for gdb. */
330 DECL_ARTIFICIAL (decl) = 1;
332 pushdecl_top_level (decl);
337 /* Finds the (global) class named NAME. Creates the class if not found.
338 Also creates associated TYPE_DECL.
339 Does not check if the class actually exists, load the class,
340 fill in field or methods, or do layout_type. */
343 lookup_class (tree name)
345 tree decl = IDENTIFIER_CLASS_VALUE (name);
346 if (decl == NULL_TREE)
347 decl = push_class (make_class (), name);
348 return TREE_TYPE (decl);
352 set_super_info (int access_flags, tree this_class,
353 tree super_class, int interfaces_count)
355 int total_supers = interfaces_count;
356 tree class_decl = TYPE_NAME (this_class);
360 TYPE_BINFO_BASETYPES (this_class) = make_tree_vec (total_supers);
363 tree super_binfo = make_tree_vec (BINFO_ELTS);
364 BINFO_TYPE (super_binfo) = super_class;
365 BINFO_OFFSET (super_binfo) = integer_zero_node;
366 TREE_VIA_PUBLIC (super_binfo) = 1;
367 TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (this_class)), 0)
369 CLASS_HAS_SUPER (this_class) = 1;
372 set_class_decl_access_flags (access_flags, class_decl);
376 set_class_decl_access_flags (int access_flags, tree class_decl)
378 if (access_flags & ACC_PUBLIC) CLASS_PUBLIC (class_decl) = 1;
379 if (access_flags & ACC_FINAL) CLASS_FINAL (class_decl) = 1;
380 if (access_flags & ACC_SUPER) CLASS_SUPER (class_decl) = 1;
381 if (access_flags & ACC_INTERFACE) CLASS_INTERFACE (class_decl) = 1;
382 if (access_flags & ACC_ABSTRACT) CLASS_ABSTRACT (class_decl) = 1;
383 if (access_flags & ACC_STATIC) CLASS_STATIC (class_decl) = 1;
384 if (access_flags & ACC_PRIVATE) CLASS_PRIVATE (class_decl) = 1;
385 if (access_flags & ACC_PROTECTED) CLASS_PROTECTED (class_decl) = 1;
386 if (access_flags & ACC_STRICT) CLASS_STRICTFP (class_decl) = 1;
389 /* Return length of inheritance chain of CLAS, where java.lang.Object is 0,
390 direct sub-classes of Object are 1, and so on. */
393 class_depth (tree clas)
396 if (! CLASS_LOADED_P (clas))
397 load_class (clas, 1);
398 if (TYPE_SIZE (clas) == error_mark_node)
400 while (clas != object_type_node)
403 clas = TYPE_BINFO_BASETYPE (clas, 0);
408 /* Return true iff TYPE2 is an interface that extends interface TYPE1 */
411 interface_of_p (tree type1, tree type2)
416 if (!(basetype_vec = TYPE_BINFO_BASETYPES (type2)))
418 n = TREE_VEC_LENGTH (basetype_vec);
419 for (i = 0; i < n; i++)
421 tree vec_elt = TREE_VEC_ELT (basetype_vec, i);
422 if (vec_elt && BINFO_TYPE (vec_elt) == type1)
425 for (i = 0; i < n; i++)
427 tree vec_elt = TREE_VEC_ELT (basetype_vec, i);
428 if (vec_elt && BINFO_TYPE (vec_elt)
429 && interface_of_p (type1, BINFO_TYPE (vec_elt)))
435 /* Return true iff TYPE1 inherits from TYPE2. */
438 inherits_from_p (tree type1, tree type2)
440 while (type1 != NULL_TREE && TREE_CODE (type1) == RECORD_TYPE)
444 type1 = CLASSTYPE_SUPER (type1);
449 /* Return a 1 iff TYPE1 is an enclosing context for TYPE2 */
452 enclosing_context_p (tree type1, tree type2)
454 if (!INNER_CLASS_TYPE_P (type2))
457 for (type2 = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type2)));
459 type2 = (INNER_CLASS_TYPE_P (type2) ?
460 TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type2))) : NULL_TREE))
469 /* Return 1 iff there exists a common enclosing context between TYPE1
472 int common_enclosing_context_p (tree type1, tree type2)
474 if (!PURE_INNER_CLASS_TYPE_P (type1) || !PURE_INNER_CLASS_TYPE_P (type2))
477 for (type1 = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type1))); type1;
478 type1 = (PURE_INNER_CLASS_TYPE_P (type1) ?
479 TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type1))) : NULL_TREE))
482 for (current = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type2))); current;
483 current = (PURE_INNER_CLASS_TYPE_P (current) ?
484 TREE_TYPE (DECL_CONTEXT (TYPE_NAME (current))) :
486 if (type1 == current)
493 add_interface_do (tree basetype_vec, tree interface_class, int i)
495 tree interface_binfo = make_tree_vec (BINFO_ELTS);
496 BINFO_TYPE (interface_binfo) = interface_class;
497 BINFO_OFFSET (interface_binfo) = integer_zero_node;
498 BINFO_VPTR_FIELD (interface_binfo) = integer_zero_node;
499 TREE_VIA_VIRTUAL (interface_binfo) = 1;
500 TREE_VIA_PUBLIC (interface_binfo) = 1;
501 TREE_VEC_ELT (basetype_vec, i) = interface_binfo;
504 /* Add INTERFACE_CLASS to THIS_CLASS iff INTERFACE_CLASS can't be
505 found in THIS_CLASS. Returns NULL_TREE upon success, INTERFACE_CLASS
506 if attempt is made to add it twice. */
509 maybe_add_interface (tree this_class, tree interface_class)
511 tree basetype_vec = TYPE_BINFO_BASETYPES (this_class);
513 int n = TREE_VEC_LENGTH (basetype_vec);
518 error ("internal error - too many interface type");
521 else if (TREE_VEC_ELT (basetype_vec, i) == NULL_TREE)
523 else if (BINFO_TYPE (TREE_VEC_ELT (basetype_vec, i)) == interface_class)
524 return interface_class;
526 add_interface_do (basetype_vec, interface_class, i);
530 /* Add the INTERFACE_CLASS as one of the interfaces of THIS_CLASS. */
533 add_interface (tree this_class, tree interface_class)
535 tree basetype_vec = TYPE_BINFO_BASETYPES (this_class);
537 int n = TREE_VEC_LENGTH (basetype_vec);
542 error ("internal error - too many interface type");
545 else if (TREE_VEC_ELT (basetype_vec, i) == NULL_TREE)
548 add_interface_do (basetype_vec, interface_class, i);
552 /* Return the address of a pointer to the first FUNCTION_DECL
553 in the list (*LIST) whose DECL_NAME is NAME. */
556 find_named_method (tree *list, tree name)
558 while (*list && DECL_NAME (*list) != name)
559 list = &TREE_CHAIN (*list);
565 build_java_method_type (tree fntype, tree this_class, int access_flags)
567 if (access_flags & ACC_STATIC)
569 return build_method_type (this_class, fntype);
573 add_method_1 (tree this_class, int access_flags, tree name, tree function_type)
575 tree method_type, fndecl;
577 method_type = build_java_method_type (function_type,
578 this_class, access_flags);
580 fndecl = build_decl (FUNCTION_DECL, name, method_type);
581 DECL_CONTEXT (fndecl) = this_class;
583 DECL_LANG_SPECIFIC (fndecl)
584 = ggc_alloc_cleared (sizeof (struct lang_decl));
585 DECL_LANG_SPECIFIC (fndecl)->desc = LANG_DECL_FUNC;
587 /* Initialize the static initializer test table. */
589 DECL_FUNCTION_INIT_TEST_TABLE (fndecl) =
590 java_treetreehash_create (10, 1);
592 /* Initialize the initialized (static) class table. */
593 if (access_flags & ACC_STATIC)
594 DECL_FUNCTION_INITIALIZED_CLASS_TABLE (fndecl) =
595 htab_create_ggc (50, htab_hash_pointer, htab_eq_pointer, NULL);
597 /* Initialize the static method invocation compound list */
598 DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (fndecl) = NULL_TREE;
600 TREE_CHAIN (fndecl) = TYPE_METHODS (this_class);
601 TYPE_METHODS (this_class) = fndecl;
603 /* Notice that this is a finalizer and update the class type
604 accordingly. This is used to optimize instance allocation. */
605 if (name == finalize_identifier_node
606 && TREE_TYPE (function_type) == void_type_node
607 && TREE_VALUE (TYPE_ARG_TYPES (function_type)) == void_type_node)
608 HAS_FINALIZER_P (this_class) = 1;
610 if (access_flags & ACC_PUBLIC) METHOD_PUBLIC (fndecl) = 1;
611 if (access_flags & ACC_PROTECTED) METHOD_PROTECTED (fndecl) = 1;
612 if (access_flags & ACC_PRIVATE)
613 METHOD_PRIVATE (fndecl) = DECL_INLINE (fndecl) = 1;
614 if (access_flags & ACC_NATIVE)
616 METHOD_NATIVE (fndecl) = 1;
617 DECL_EXTERNAL (fndecl) = 1;
619 if (access_flags & ACC_STATIC)
620 METHOD_STATIC (fndecl) = DECL_INLINE (fndecl) = 1;
621 if (access_flags & ACC_FINAL)
622 METHOD_FINAL (fndecl) = DECL_INLINE (fndecl) = 1;
623 if (access_flags & ACC_SYNCHRONIZED) METHOD_SYNCHRONIZED (fndecl) = 1;
624 if (access_flags & ACC_ABSTRACT) METHOD_ABSTRACT (fndecl) = 1;
625 if (access_flags & ACC_TRANSIENT) METHOD_TRANSIENT (fndecl) = 1;
626 if (access_flags & ACC_STRICT) METHOD_STRICTFP (fndecl) = 1;
630 /* Add a method to THIS_CLASS.
631 The method's name is NAME.
632 Its signature (mangled type) is METHOD_SIG (an IDENTIFIER_NODE). */
635 add_method (tree this_class, int access_flags, tree name, tree method_sig)
637 tree function_type, fndecl;
638 const unsigned char *sig
639 = (const unsigned char *) IDENTIFIER_POINTER (method_sig);
642 fatal_error ("bad method signature");
644 function_type = get_type_from_signature (method_sig);
645 fndecl = add_method_1 (this_class, access_flags, name, function_type);
646 set_java_signature (TREE_TYPE (fndecl), method_sig);
651 add_field (tree class, tree name, tree field_type, int flags)
653 int is_static = (flags & ACC_STATIC) != 0;
655 field = build_decl (is_static ? VAR_DECL : FIELD_DECL, name, field_type);
656 TREE_CHAIN (field) = TYPE_FIELDS (class);
657 TYPE_FIELDS (class) = field;
658 DECL_CONTEXT (field) = class;
660 if (flags & ACC_PUBLIC) FIELD_PUBLIC (field) = 1;
661 if (flags & ACC_PROTECTED) FIELD_PROTECTED (field) = 1;
662 if (flags & ACC_PRIVATE) FIELD_PRIVATE (field) = 1;
663 if (flags & ACC_FINAL) FIELD_FINAL (field) = 1;
664 if (flags & ACC_VOLATILE) FIELD_VOLATILE (field) = 1;
665 if (flags & ACC_TRANSIENT) FIELD_TRANSIENT (field) = 1;
668 FIELD_STATIC (field) = 1;
669 /* Always make field externally visible. This is required so
670 that native methods can always access the field. */
671 TREE_PUBLIC (field) = 1;
672 /* Considered external until we know what classes are being
673 compiled into this object file. */
674 DECL_EXTERNAL (field) = 1;
680 /* Associate a constant value CONSTANT with VAR_DECL FIELD. */
683 set_constant_value (tree field, tree constant)
685 if (field == NULL_TREE)
686 warning ("misplaced ConstantValue attribute (not in any field)");
687 else if (DECL_INITIAL (field) != NULL_TREE)
688 warning ("duplicate ConstantValue attribute for field '%s'",
689 IDENTIFIER_POINTER (DECL_NAME (field)));
692 DECL_INITIAL (field) = constant;
693 if (TREE_TYPE (constant) != TREE_TYPE (field)
694 && ! (TREE_TYPE (constant) == int_type_node
695 && INTEGRAL_TYPE_P (TREE_TYPE (field))
696 && TYPE_PRECISION (TREE_TYPE (field)) <= 32)
697 && ! (TREE_TYPE (constant) == utf8const_ptr_type
698 && TREE_TYPE (field) == string_ptr_type_node))
699 error ("ConstantValue attribute of field '%s' has wrong type",
700 IDENTIFIER_POINTER (DECL_NAME (field)));
701 if (FIELD_FINAL (field))
702 DECL_FIELD_FINAL_IUD (field) = 1;
706 /* Count the number of Unicode chars encoded in a given Ut8 string. */
710 strLengthUtf8 (char *str, int len)
712 register unsigned char* ptr = (unsigned char*) str;
713 register unsigned char *limit = ptr + len;
715 for (; ptr < limit; str_length++) {
716 if (UTF8_GET (ptr, limit) < 0)
724 /* Calculate a hash value for a string encoded in Utf8 format.
725 * This returns the same hash value as specified for java.lang.String.hashCode.
729 hashUtf8String (const char *str, int len)
731 register const unsigned char* ptr = (const unsigned char*) str;
732 register const unsigned char *limit = ptr + len;
736 int ch = UTF8_GET (ptr, limit);
737 /* Updated specification from
738 http://www.javasoft.com/docs/books/jls/clarify.html. */
739 hash = (31 * hash) + ch;
744 static GTY(()) tree utf8_decl_list = NULL_TREE;
747 build_utf8_ref (tree name)
749 const char * name_ptr = IDENTIFIER_POINTER(name);
750 int name_len = IDENTIFIER_LENGTH(name);
752 tree ctype, field = NULL_TREE, str_type, cinit, string;
753 static int utf8_count = 0;
755 tree ref = IDENTIFIER_UTF8_REF (name);
757 if (ref != NULL_TREE)
760 ctype = make_node (RECORD_TYPE);
761 str_type = build_prim_array_type (unsigned_byte_type_node,
762 name_len + 1); /* Allow for final '\0'. */
763 PUSH_FIELD (ctype, field, "hash", unsigned_short_type_node);
764 PUSH_FIELD (ctype, field, "length", unsigned_short_type_node);
765 PUSH_FIELD (ctype, field, "data", str_type);
766 FINISH_RECORD (ctype);
767 START_RECORD_CONSTRUCTOR (cinit, ctype);
768 name_hash = hashUtf8String (name_ptr, name_len) & 0xFFFF;
769 PUSH_FIELD_VALUE (cinit, "hash", build_int_2 (name_hash, 0));
770 PUSH_FIELD_VALUE (cinit, "length", build_int_2 (name_len, 0));
771 string = build_string (name_len, name_ptr);
772 TREE_TYPE (string) = str_type;
773 PUSH_FIELD_VALUE (cinit, "data", string);
774 FINISH_RECORD_CONSTRUCTOR (cinit);
775 TREE_CONSTANT (cinit) = 1;
777 /* Generate a unique-enough identifier. */
778 sprintf(buf, "_Utf%d", ++utf8_count);
780 decl = build_decl (VAR_DECL, get_identifier (buf), utf8const_type);
781 TREE_STATIC (decl) = 1;
782 DECL_ARTIFICIAL (decl) = 1;
783 DECL_IGNORED_P (decl) = 1;
784 TREE_READONLY (decl) = 1;
785 TREE_THIS_VOLATILE (decl) = 0;
786 DECL_INITIAL (decl) = cinit;
787 #ifdef HAVE_GAS_SHF_MERGE
790 /* Ensure decl_size is a multiple of utf8const_type's alignment. */
791 decl_size = (name_len + 5 + TYPE_ALIGN_UNIT (utf8const_type) - 1)
792 & ~(TYPE_ALIGN_UNIT (utf8const_type) - 1);
793 if (flag_merge_constants && decl_size < 256)
796 int flags = (SECTION_OVERRIDE
797 | SECTION_MERGE | (SECTION_ENTSIZE & decl_size));
798 sprintf (buf, ".rodata.jutf8.%d", decl_size);
799 named_section_flags (buf, flags);
800 DECL_SECTION_NAME (decl) = build_string (strlen (buf), buf);
804 TREE_CHAIN (decl) = utf8_decl_list;
805 layout_decl (decl, 0);
807 rest_of_decl_compilation (decl, (char*) 0, global_bindings_p (), 0);
808 utf8_decl_list = decl;
809 make_decl_rtl (decl, (char*) 0);
810 ref = build1 (ADDR_EXPR, utf8const_ptr_type, decl);
811 IDENTIFIER_UTF8_REF (name) = ref;
815 /* Build a reference to the class TYPE.
816 Also handles primitive types and array types. */
819 build_class_ref (tree type)
821 int is_compiled = is_compiled_class (type);
824 tree ref, decl_name, decl;
825 if (TREE_CODE (type) == POINTER_TYPE)
826 type = TREE_TYPE (type);
827 if (TREE_CODE (type) == RECORD_TYPE)
829 if (TYPE_SIZE (type) == error_mark_node)
830 return null_pointer_node;
831 decl_name = identifier_subst (DECL_NAME (TYPE_NAME (type)),
832 "", '/', '/', ".class");
833 decl = IDENTIFIER_GLOBAL_VALUE (decl_name);
834 if (decl == NULL_TREE)
836 decl = build_decl (VAR_DECL, decl_name, class_type_node);
837 DECL_SIZE (decl) = TYPE_SIZE (class_type_node);
838 DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (class_type_node);
839 TREE_STATIC (decl) = 1;
840 TREE_PUBLIC (decl) = 1;
841 DECL_IGNORED_P (decl) = 1;
842 DECL_ARTIFICIAL (decl) = 1;
843 if (is_compiled == 1)
844 DECL_EXTERNAL (decl) = 1;
845 SET_DECL_ASSEMBLER_NAME (decl,
846 java_mangle_class_field
847 (&temporary_obstack, type));
848 make_decl_rtl (decl, NULL);
849 pushdecl_top_level (decl);
856 if (flag_emit_class_files)
858 const char *prim_class_name;
860 if (type == char_type_node)
861 prim_class_name = "java.lang.Character";
862 else if (type == boolean_type_node)
863 prim_class_name = "java.lang.Boolean";
864 else if (type == byte_type_node)
865 prim_class_name = "java.lang.Byte";
866 else if (type == short_type_node)
867 prim_class_name = "java.lang.Short";
868 else if (type == int_type_node)
869 prim_class_name = "java.lang.Integer";
870 else if (type == long_type_node)
871 prim_class_name = "java.lang.Long";
872 else if (type == float_type_node)
873 prim_class_name = "java.lang.Float";
874 else if (type == double_type_node)
875 prim_class_name = "java.lang.Double";
876 else if (type == void_type_node)
877 prim_class_name = "java.lang.Void";
881 prim_class = lookup_class (get_identifier (prim_class_name));
882 return build (COMPONENT_REF, NULL_TREE,
883 prim_class, TYPE_identifier_node);
885 decl_name = TYPE_NAME (type);
886 if (TREE_CODE (decl_name) == TYPE_DECL)
887 decl_name = DECL_NAME (decl_name);
888 name = IDENTIFIER_POINTER (decl_name);
889 if (strncmp (name, "promoted_", 9) == 0)
891 sprintf (buffer, "_Jv_%sClass", name);
892 decl_name = get_identifier (buffer);
893 decl = IDENTIFIER_GLOBAL_VALUE (decl_name);
894 if (decl == NULL_TREE)
896 decl = build_decl (VAR_DECL, decl_name, class_type_node);
897 TREE_STATIC (decl) = 1;
898 TREE_PUBLIC (decl) = 1;
899 DECL_EXTERNAL (decl) = 1;
900 make_decl_rtl (decl, NULL);
901 pushdecl_top_level (decl);
905 ref = build1 (ADDR_EXPR, class_ptr_type, decl);
912 index = alloc_class_constant (type);
913 cl = build_ref_from_constant_pool (index);
914 TREE_TYPE (cl) = promote_type (class_ptr_type);
920 build_static_field_ref (tree fdecl)
922 tree fclass = DECL_CONTEXT (fdecl);
923 int is_compiled = is_compiled_class (fclass);
925 /* Allow static final fields to fold to a constant. When using
926 -fno-assume-compiled, gcj will sometimes try to fold a field from
927 an uncompiled class. This is required when the field in question
928 meets the appropriate criteria for a compile-time constant.
929 However, currently sometimes gcj is too eager and will end up
930 returning the field itself, leading to an incorrect external
931 reference being generated. */
933 || (FIELD_FINAL (fdecl) && DECL_INITIAL (fdecl) != NULL_TREE
934 && (JSTRING_TYPE_P (TREE_TYPE (fdecl))
935 || JNUMERIC_TYPE_P (TREE_TYPE (fdecl)))
936 && TREE_CONSTANT (DECL_INITIAL (fdecl))))
938 if (!DECL_RTL_SET_P (fdecl))
940 if (is_compiled == 1)
941 DECL_EXTERNAL (fdecl) = 1;
942 make_decl_rtl (fdecl, NULL);
949 * *(FTYPE*)build_class_ref(FCLASS)->fields[INDEX].info.addr */
950 tree ref = build_class_ref (fclass);
953 ref = build1 (INDIRECT_REF, class_type_node, ref);
954 ref = build (COMPONENT_REF, field_ptr_type_node, ref,
955 lookup_field (&class_type_node, fields_ident));
957 for (fld = TYPE_FIELDS (fclass); ; fld = TREE_CHAIN (fld))
961 if (fld == NULL_TREE)
962 fatal_error ("field '%s' not found in class",
963 IDENTIFIER_POINTER (DECL_NAME (fdecl)));
964 if (FIELD_STATIC (fld))
967 field_index *= int_size_in_bytes (field_type_node);
968 ref = fold (build (PLUS_EXPR, field_ptr_type_node,
969 ref, build_int_2 (field_index, 0)));
970 ref = build1 (INDIRECT_REF, field_type_node, ref);
971 ref = build (COMPONENT_REF, field_info_union_node,
972 ref, lookup_field (&field_type_node, info_ident));
973 ref = build (COMPONENT_REF, ptr_type_node,
974 ref, TREE_CHAIN (TYPE_FIELDS (field_info_union_node)));
975 return fold (build1 (INDIRECT_REF, TREE_TYPE(fdecl), ref));
980 get_access_flags_from_decl (tree decl)
982 int access_flags = 0;
983 if (TREE_CODE (decl) == FIELD_DECL || TREE_CODE (decl) == VAR_DECL)
985 if (FIELD_STATIC (decl))
986 access_flags |= ACC_STATIC;
987 if (FIELD_PUBLIC (decl))
988 access_flags |= ACC_PUBLIC;
989 if (FIELD_PROTECTED (decl))
990 access_flags |= ACC_PROTECTED;
991 if (FIELD_PRIVATE (decl))
992 access_flags |= ACC_PRIVATE;
993 if (FIELD_FINAL (decl))
994 access_flags |= ACC_FINAL;
995 if (FIELD_VOLATILE (decl))
996 access_flags |= ACC_VOLATILE;
997 if (FIELD_TRANSIENT (decl))
998 access_flags |= ACC_TRANSIENT;
1001 if (TREE_CODE (decl) == TYPE_DECL)
1003 if (CLASS_PUBLIC (decl))
1004 access_flags |= ACC_PUBLIC;
1005 if (CLASS_FINAL (decl))
1006 access_flags |= ACC_FINAL;
1007 if (CLASS_SUPER (decl))
1008 access_flags |= ACC_SUPER;
1009 if (CLASS_INTERFACE (decl))
1010 access_flags |= ACC_INTERFACE;
1011 if (CLASS_ABSTRACT (decl))
1012 access_flags |= ACC_ABSTRACT;
1013 if (CLASS_STATIC (decl))
1014 access_flags |= ACC_STATIC;
1015 if (CLASS_PRIVATE (decl))
1016 access_flags |= ACC_PRIVATE;
1017 if (CLASS_PROTECTED (decl))
1018 access_flags |= ACC_PROTECTED;
1019 if (CLASS_STRICTFP (decl))
1020 access_flags |= ACC_STRICT;
1021 return access_flags;
1023 if (TREE_CODE (decl) == FUNCTION_DECL)
1025 if (METHOD_PUBLIC (decl))
1026 access_flags |= ACC_PUBLIC;
1027 if (METHOD_PRIVATE (decl))
1028 access_flags |= ACC_PRIVATE;
1029 if (METHOD_PROTECTED (decl))
1030 access_flags |= ACC_PROTECTED;
1031 if (METHOD_STATIC (decl))
1032 access_flags |= ACC_STATIC;
1033 if (METHOD_FINAL (decl))
1034 access_flags |= ACC_FINAL;
1035 if (METHOD_SYNCHRONIZED (decl))
1036 access_flags |= ACC_SYNCHRONIZED;
1037 if (METHOD_NATIVE (decl))
1038 access_flags |= ACC_NATIVE;
1039 if (METHOD_ABSTRACT (decl))
1040 access_flags |= ACC_ABSTRACT;
1041 if (METHOD_TRANSIENT (decl))
1042 access_flags |= ACC_TRANSIENT;
1043 if (METHOD_STRICTFP (decl))
1044 access_flags |= ACC_STRICT;
1045 return access_flags;
1051 make_field_value (tree fdecl)
1055 tree type = TREE_TYPE (fdecl);
1056 int resolved = is_compiled_class (type);
1058 START_RECORD_CONSTRUCTOR (finit, field_type_node);
1059 PUSH_FIELD_VALUE (finit, "name", build_utf8_ref (DECL_NAME (fdecl)));
1061 type = build_class_ref (type);
1064 tree signature = build_java_signature (type);
1066 type = build_utf8_ref (unmangle_classname
1067 (IDENTIFIER_POINTER (signature),
1068 IDENTIFIER_LENGTH (signature)));
1070 PUSH_FIELD_VALUE (finit, "type", type);
1072 flags = get_access_flags_from_decl (fdecl);
1074 flags |= 0x8000 /* FIELD_UNRESOLVED_FLAG */;
1076 PUSH_FIELD_VALUE (finit, "accflags", build_int_2 (flags, 0));
1077 PUSH_FIELD_VALUE (finit, "bsize", TYPE_SIZE_UNIT (TREE_TYPE (fdecl)));
1081 build (CONSTRUCTOR, field_info_union_node, NULL_TREE,
1083 ((FIELD_STATIC (fdecl)
1084 ? TREE_CHAIN (TYPE_FIELDS (field_info_union_node))
1085 : TYPE_FIELDS (field_info_union_node)),
1086 (FIELD_STATIC (fdecl)
1087 ? build_address_of (build_static_field_ref (fdecl))
1088 : byte_position (fdecl)))));
1090 FINISH_RECORD_CONSTRUCTOR (finit);
1095 make_method_value (tree mdecl)
1097 static int method_name_count = 0;
1101 #define ACC_TRANSLATED 0x4000
1102 int accflags = get_access_flags_from_decl (mdecl) | ACC_TRANSLATED;
1104 if (!flag_indirect_dispatch && DECL_VINDEX (mdecl) != NULL_TREE)
1105 index = DECL_VINDEX (mdecl);
1107 index = integer_minus_one_node;
1109 code = null_pointer_node;
1110 if (DECL_RTL_SET_P (mdecl))
1111 code = build1 (ADDR_EXPR, nativecode_ptr_type_node, mdecl);
1112 START_RECORD_CONSTRUCTOR (minit, method_type_node);
1113 PUSH_FIELD_VALUE (minit, "name",
1114 build_utf8_ref (DECL_CONSTRUCTOR_P (mdecl) ?
1115 init_identifier_node
1116 : DECL_NAME (mdecl)));
1118 tree signature = build_java_signature (TREE_TYPE (mdecl));
1119 PUSH_FIELD_VALUE (minit, "signature",
1122 (IDENTIFIER_POINTER(signature),
1123 IDENTIFIER_LENGTH(signature)))));
1125 PUSH_FIELD_VALUE (minit, "accflags", build_int_2 (accflags, 0));
1126 PUSH_FIELD_VALUE (minit, "index", index);
1127 PUSH_FIELD_VALUE (minit, "ncode", code);
1130 /* Compute the `throws' information for the method. */
1131 tree table = null_pointer_node;
1132 if (DECL_FUNCTION_THROWS (mdecl) != NULL_TREE)
1134 int length = 1 + list_length (DECL_FUNCTION_THROWS (mdecl));
1135 tree iter, type, array;
1138 table = tree_cons (NULL_TREE, table, NULL_TREE);
1139 for (iter = DECL_FUNCTION_THROWS (mdecl);
1141 iter = TREE_CHAIN (iter))
1143 tree sig = DECL_NAME (TYPE_NAME (TREE_VALUE (iter)));
1145 = build_utf8_ref (unmangle_classname (IDENTIFIER_POINTER (sig),
1146 IDENTIFIER_LENGTH (sig)));
1147 table = tree_cons (NULL_TREE, utf8, table);
1149 type = build_prim_array_type (ptr_type_node, length);
1150 table = build (CONSTRUCTOR, type, NULL_TREE, table);
1151 /* Compute something unique enough. */
1152 sprintf (buf, "_methods%d", method_name_count++);
1153 array = build_decl (VAR_DECL, get_identifier (buf), type);
1154 DECL_INITIAL (array) = table;
1155 TREE_STATIC (array) = 1;
1156 DECL_ARTIFICIAL (array) = 1;
1157 DECL_IGNORED_P (array) = 1;
1158 rest_of_decl_compilation (array, (char*) 0, 1, 0);
1160 table = build1 (ADDR_EXPR, ptr_type_node, array);
1163 PUSH_FIELD_VALUE (minit, "throws", table);
1166 FINISH_RECORD_CONSTRUCTOR (minit);
1171 get_dispatch_vector (tree type)
1173 tree vtable = TYPE_VTABLE (type);
1175 if (vtable == NULL_TREE)
1179 tree super = CLASSTYPE_SUPER (type);
1180 HOST_WIDE_INT nvirtuals = tree_low_cst (TYPE_NVIRTUALS (type), 0);
1181 vtable = make_tree_vec (nvirtuals);
1182 TYPE_VTABLE (type) = vtable;
1183 if (super != NULL_TREE)
1185 tree super_vtable = get_dispatch_vector (super);
1187 for (i = tree_low_cst (TYPE_NVIRTUALS (super), 0); --i >= 0; )
1188 TREE_VEC_ELT (vtable, i) = TREE_VEC_ELT (super_vtable, i);
1191 for (method = TYPE_METHODS (type); method != NULL_TREE;
1192 method = TREE_CHAIN (method))
1193 if (DECL_VINDEX (method) != NULL_TREE
1194 && host_integerp (DECL_VINDEX (method), 0))
1195 TREE_VEC_ELT (vtable, tree_low_cst (DECL_VINDEX (method), 0))
1203 get_dispatch_table (tree type, tree this_class_addr)
1205 int abstract_p = CLASS_ABSTRACT (TYPE_NAME (type));
1206 tree vtable = get_dispatch_vector (type);
1208 tree list = NULL_TREE;
1209 int nvirtuals = TREE_VEC_LENGTH (vtable);
1213 for (i = nvirtuals; --i >= 0; )
1215 tree method = TREE_VEC_ELT (vtable, i);
1216 if (METHOD_ABSTRACT (method))
1219 warning_with_decl (method,
1220 "abstract method in non-abstract class");
1222 if (TARGET_VTABLE_USES_DESCRIPTORS)
1223 for (j = 0; j < TARGET_VTABLE_USES_DESCRIPTORS; ++j)
1224 list = tree_cons (NULL_TREE, null_pointer_node, list);
1226 list = tree_cons (NULL_TREE, null_pointer_node, list);
1230 if (!DECL_RTL_SET_P (method))
1231 make_decl_rtl (method, NULL);
1233 if (TARGET_VTABLE_USES_DESCRIPTORS)
1234 for (j = 0; j < TARGET_VTABLE_USES_DESCRIPTORS; ++j)
1236 tree fdesc = build (FDESC_EXPR, nativecode_ptr_type_node,
1237 method, build_int_2 (j, 0));
1238 TREE_CONSTANT (fdesc) = 1;
1239 list = tree_cons (NULL_TREE, fdesc, list);
1242 list = tree_cons (NULL_TREE,
1243 build1 (ADDR_EXPR, nativecode_ptr_type_node,
1249 /* Dummy entry for compatibility with G++ -fvtable-thunks. When
1250 using the Boehm GC we sometimes stash a GC type descriptor
1251 there. We set the PURPOSE to NULL_TREE not to interfere (reset)
1252 the emitted byte count during the output to the assembly file. */
1253 /* With TARGET_VTABLE_USES_DESCRIPTORS, we only add one extra
1254 fake "function descriptor". It's first word is the is the class
1255 pointer, and subsequent words (usually one) contain the GC descriptor.
1256 In all other cases, we reserve two extra vtable slots. */
1257 gc_descr = get_boehm_type_descriptor (type);
1258 list = tree_cons (NULL_TREE, gc_descr, list);
1259 for (j = 1; j < TARGET_VTABLE_USES_DESCRIPTORS-1; ++j)
1260 list = tree_cons (NULL_TREE, gc_descr, list);
1261 list = tree_cons (NULL_TREE, this_class_addr, list);
1263 /** Pointer to type_info object (to be implemented), according to g++ ABI. */
1264 list = tree_cons (NULL_TREE, null_pointer_node, list);
1265 /** Offset to start of whole object. Always (ptrdiff_t)0 for Java. */
1266 list = tree_cons (integer_zero_node, null_pointer_node, list);
1268 arraysize = (TARGET_VTABLE_USES_DESCRIPTORS? nvirtuals + 1 : nvirtuals + 2);
1269 if (TARGET_VTABLE_USES_DESCRIPTORS)
1270 arraysize *= TARGET_VTABLE_USES_DESCRIPTORS;
1272 return build (CONSTRUCTOR,
1273 build_prim_array_type (nativecode_ptr_type_node, arraysize),
1278 supers_all_compiled (tree type)
1280 while (type != NULL_TREE)
1282 if (!assume_compiled (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)))))
1284 type = CLASSTYPE_SUPER (type);
1290 make_class_data (tree type)
1292 tree decl, cons, temp;
1293 tree field, fields_decl;
1294 tree static_fields = NULL_TREE;
1295 tree instance_fields = NULL_TREE;
1296 HOST_WIDE_INT static_field_count = 0;
1297 HOST_WIDE_INT instance_field_count = 0;
1298 HOST_WIDE_INT field_count;
1299 tree field_array_type;
1301 tree methods = NULL_TREE;
1302 tree dtable_decl = NULL_TREE;
1303 HOST_WIDE_INT method_count = 0;
1304 tree method_array_type;
1307 tree this_class_addr;
1308 tree constant_pool_constructor;
1309 tree interfaces = null_pointer_node;
1310 int interface_len = 0;
1311 tree type_decl = TYPE_NAME (type);
1312 /** Offset from start of virtual function table declaration
1313 to where objects actually point at, following new g++ ABI. */
1314 tree dtable_start_offset = build_int_2 (2 * POINTER_SIZE / BITS_PER_UNIT, 0);
1316 this_class_addr = build_class_ref (type);
1317 decl = TREE_OPERAND (this_class_addr, 0);
1319 /* Build Field array. */
1320 field = TYPE_FIELDS (type);
1321 if (DECL_NAME (field) == NULL_TREE)
1322 field = TREE_CHAIN (field); /* Skip dummy field for inherited data. */
1323 for ( ; field != NULL_TREE; field = TREE_CHAIN (field))
1325 if (! DECL_ARTIFICIAL (field))
1327 tree init = make_field_value (field);
1328 if (FIELD_STATIC (field))
1330 tree initial = DECL_INITIAL (field);
1331 static_field_count++;
1332 static_fields = tree_cons (NULL_TREE, init, static_fields);
1333 /* If the initial value is a string constant,
1334 prevent output_constant from trying to assemble the value. */
1335 if (initial != NULL_TREE
1336 && TREE_TYPE (initial) == string_ptr_type_node)
1337 DECL_INITIAL (field) = NULL_TREE;
1338 rest_of_decl_compilation (field, (char*) 0, 1, 1);
1339 DECL_INITIAL (field) = initial;
1343 instance_field_count++;
1344 instance_fields = tree_cons (NULL_TREE, init, instance_fields);
1348 field_count = static_field_count + instance_field_count;
1349 if (field_count > 0)
1351 static_fields = nreverse (static_fields);
1352 instance_fields = nreverse (instance_fields);
1353 static_fields = chainon (static_fields, instance_fields);
1354 field_array_type = build_prim_array_type (field_type_node, field_count);
1355 fields_decl = build_decl (VAR_DECL, mangled_classname ("_FL_", type),
1357 DECL_INITIAL (fields_decl) = build (CONSTRUCTOR, field_array_type,
1358 NULL_TREE, static_fields);
1359 TREE_STATIC (fields_decl) = 1;
1360 DECL_ARTIFICIAL (fields_decl) = 1;
1361 DECL_IGNORED_P (fields_decl) = 1;
1362 rest_of_decl_compilation (fields_decl, (char*) 0, 1, 0);
1365 fields_decl = NULL_TREE;
1367 /* Build Method array. */
1368 for (method = TYPE_METHODS (type);
1369 method != NULL_TREE; method = TREE_CHAIN (method))
1372 if (METHOD_PRIVATE (method)
1373 && ! flag_keep_inline_functions
1374 && (flag_inline_functions || optimize))
1376 init = make_method_value (method);
1378 methods = tree_cons (NULL_TREE, init, methods);
1380 method_array_type = build_prim_array_type (method_type_node, method_count);
1381 methods_decl = build_decl (VAR_DECL, mangled_classname ("_MT_", type),
1383 DECL_INITIAL (methods_decl) = build (CONSTRUCTOR, method_array_type,
1384 NULL_TREE, nreverse (methods));
1385 TREE_STATIC (methods_decl) = 1;
1386 DECL_ARTIFICIAL (methods_decl) = 1;
1387 DECL_IGNORED_P (methods_decl) = 1;
1388 rest_of_decl_compilation (methods_decl, (char*) 0, 1, 0);
1390 if (supers_all_compiled (type) && ! CLASS_INTERFACE (type_decl)
1391 && !flag_indirect_dispatch)
1393 tree dtable = get_dispatch_table (type, this_class_addr);
1394 dtable_decl = build_dtable_decl (type);
1395 DECL_INITIAL (dtable_decl) = dtable;
1396 TREE_STATIC (dtable_decl) = 1;
1397 DECL_ARTIFICIAL (dtable_decl) = 1;
1398 DECL_IGNORED_P (dtable_decl) = 1;
1399 TREE_PUBLIC (dtable_decl) = 1;
1400 rest_of_decl_compilation (dtable_decl, (char*) 0, 1, 0);
1401 if (type == class_type_node)
1402 class_dtable_decl = dtable_decl;
1405 if (class_dtable_decl == NULL_TREE)
1407 class_dtable_decl = build_dtable_decl (class_type_node);
1408 TREE_STATIC (class_dtable_decl) = 1;
1409 DECL_ARTIFICIAL (class_dtable_decl) = 1;
1410 DECL_IGNORED_P (class_dtable_decl) = 1;
1411 if (is_compiled_class (class_type_node) != 2)
1412 DECL_EXTERNAL (class_dtable_decl) = 1;
1413 rest_of_decl_compilation (class_dtable_decl, (char*) 0, 1, 0);
1416 super = CLASSTYPE_SUPER (type);
1417 if (super == NULL_TREE)
1418 super = null_pointer_node;
1419 else if (assume_compiled (IDENTIFIER_POINTER (DECL_NAME (type_decl)))
1420 && assume_compiled (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (super)))))
1421 super = build_class_ref (super);
1424 int super_index = alloc_class_constant (super);
1425 super = build_int_2 (super_index, 0);
1426 TREE_TYPE (super) = ptr_type_node;
1429 /* Build and emit the array of implemented interfaces. */
1430 if (type != object_type_node)
1431 interface_len = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type)) - 1;
1432 if (interface_len > 0)
1434 tree init = NULL_TREE;
1436 tree interface_array_type, idecl;
1437 interface_array_type
1438 = build_prim_array_type (class_ptr_type, interface_len);
1439 idecl = build_decl (VAR_DECL, mangled_classname ("_IF_", type),
1440 interface_array_type);
1441 for (i = interface_len; i > 0; i--)
1443 tree child = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (type), i);
1444 tree iclass = BINFO_TYPE (child);
1446 if (assume_compiled (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (iclass)))))
1447 index = build_class_ref (iclass);
1450 int int_index = alloc_class_constant (iclass);
1451 index = build_int_2 (int_index, 0);
1452 TREE_TYPE (index) = ptr_type_node;
1454 init = tree_cons (NULL_TREE, index, init);
1456 DECL_INITIAL (idecl) = build (CONSTRUCTOR, interface_array_type,
1458 TREE_STATIC (idecl) = 1;
1459 DECL_ARTIFICIAL (idecl) = 1;
1460 DECL_IGNORED_P (idecl) = 1;
1461 interfaces = build1 (ADDR_EXPR, ptr_type_node, idecl);
1462 rest_of_decl_compilation (idecl, (char*) 0, 1, 0);
1465 constant_pool_constructor = build_constants_constructor ();
1467 START_RECORD_CONSTRUCTOR (temp, object_type_node);
1468 PUSH_FIELD_VALUE (temp, "vtable",
1469 build (PLUS_EXPR, dtable_ptr_type,
1470 build1 (ADDR_EXPR, dtable_ptr_type, class_dtable_decl),
1471 dtable_start_offset));
1472 if (! flag_hash_synchronization)
1473 PUSH_FIELD_VALUE (temp, "sync_info", null_pointer_node);
1474 FINISH_RECORD_CONSTRUCTOR (temp);
1475 START_RECORD_CONSTRUCTOR (cons, class_type_node);
1476 PUSH_SUPER_VALUE (cons, temp);
1477 PUSH_FIELD_VALUE (cons, "next", null_pointer_node);
1478 PUSH_FIELD_VALUE (cons, "name", build_utf8_ref (DECL_NAME (type_decl)));
1479 PUSH_FIELD_VALUE (cons, "accflags",
1480 build_int_2 (get_access_flags_from_decl (type_decl), 0));
1482 PUSH_FIELD_VALUE (cons, "superclass",
1483 CLASS_INTERFACE (type_decl) ? null_pointer_node : super);
1484 PUSH_FIELD_VALUE (cons, "constants", constant_pool_constructor);
1485 PUSH_FIELD_VALUE (cons, "methods",
1486 build1 (ADDR_EXPR, method_ptr_type_node, methods_decl));
1487 PUSH_FIELD_VALUE (cons, "method_count", build_int_2 (method_count, 0));
1489 if (flag_indirect_dispatch)
1490 PUSH_FIELD_VALUE (cons, "vtable_method_count", integer_minus_one_node)
1492 PUSH_FIELD_VALUE (cons, "vtable_method_count", TYPE_NVIRTUALS (type));
1494 PUSH_FIELD_VALUE (cons, "fields",
1495 fields_decl == NULL_TREE ? null_pointer_node
1496 : build1 (ADDR_EXPR, field_ptr_type_node, fields_decl));
1497 PUSH_FIELD_VALUE (cons, "size_in_bytes", size_in_bytes (type));
1498 PUSH_FIELD_VALUE (cons, "field_count", build_int_2 (field_count, 0));
1499 PUSH_FIELD_VALUE (cons, "static_field_count",
1500 build_int_2 (static_field_count, 0));
1502 if (flag_indirect_dispatch)
1503 PUSH_FIELD_VALUE (cons, "vtable", null_pointer_node)
1505 PUSH_FIELD_VALUE (cons, "vtable",
1506 dtable_decl == NULL_TREE ? null_pointer_node
1507 : build (PLUS_EXPR, dtable_ptr_type,
1508 build1 (ADDR_EXPR, dtable_ptr_type, dtable_decl),
1509 dtable_start_offset));
1511 if (otable_methods == NULL_TREE)
1513 PUSH_FIELD_VALUE (cons, "otable", null_pointer_node);
1514 PUSH_FIELD_VALUE (cons, "otable_syms", null_pointer_node);
1518 PUSH_FIELD_VALUE (cons, "otable",
1519 build1 (ADDR_EXPR, otable_ptr_type, otable_decl));
1520 PUSH_FIELD_VALUE (cons, "otable_syms",
1521 build1 (ADDR_EXPR, method_symbols_array_ptr_type,
1524 PUSH_FIELD_VALUE (cons, "interfaces", interfaces);
1525 PUSH_FIELD_VALUE (cons, "loader", null_pointer_node);
1526 PUSH_FIELD_VALUE (cons, "interface_count", build_int_2 (interface_len, 0));
1527 PUSH_FIELD_VALUE (cons, "state", integer_zero_node);
1529 PUSH_FIELD_VALUE (cons, "thread", null_pointer_node);
1530 PUSH_FIELD_VALUE (cons, "depth", integer_zero_node);
1531 PUSH_FIELD_VALUE (cons, "ancestors", null_pointer_node);
1532 PUSH_FIELD_VALUE (cons, "idt", null_pointer_node);
1533 PUSH_FIELD_VALUE (cons, "arrayclass", null_pointer_node);
1534 PUSH_FIELD_VALUE (cons, "protectionDomain", null_pointer_node);
1535 PUSH_FIELD_VALUE (cons, "chain", null_pointer_node);
1537 FINISH_RECORD_CONSTRUCTOR (cons);
1539 DECL_INITIAL (decl) = cons;
1541 /* Hash synchronization requires at least 64-bit alignment. */
1542 if (flag_hash_synchronization && POINTER_SIZE < 64)
1543 DECL_ALIGN (decl) = 64;
1545 rest_of_decl_compilation (decl, (char*) 0, 1, 0);
1552 tree type_methods = TYPE_METHODS (current_class);
1553 int saw_native_method = 0;
1555 /* Find out if we have any native methods. We use this information
1557 for (method = type_methods;
1558 method != NULL_TREE;
1559 method = TREE_CHAIN (method))
1561 if (METHOD_NATIVE (method))
1563 saw_native_method = 1;
1568 /* Emit deferred inline methods. */
1569 for (method = type_methods; method != NULL_TREE; )
1571 if (! TREE_ASM_WRITTEN (method) && DECL_SAVED_INSNS (method) != 0)
1573 output_inline_function (method);
1574 /* Scan the list again to see if there are any earlier
1576 method = type_methods;
1579 method = TREE_CHAIN (method);
1582 current_function_decl = NULL_TREE;
1583 make_class_data (current_class);
1585 rest_of_decl_compilation (TYPE_NAME (current_class), (char*) 0, 1, 0);
1588 /* Return 2 if CLASS is compiled by this compilation job;
1589 return 1 if CLASS can otherwise be assumed to be compiled;
1590 return 0 if we cannot assume that CLASS is compiled.
1591 Returns 1 for primitive and 0 for array types. */
1593 is_compiled_class (tree class)
1596 if (TREE_CODE (class) == POINTER_TYPE)
1597 class = TREE_TYPE (class);
1598 if (TREE_CODE (class) != RECORD_TYPE) /* Primitive types are static. */
1600 if (TYPE_ARRAY_P (class))
1602 if (class == current_class)
1605 seen_in_zip = (TYPE_JCF (class) && JCF_SEEN_IN_ZIP (TYPE_JCF (class)));
1606 if (CLASS_FROM_CURRENTLY_COMPILED_P (class) || seen_in_zip)
1608 /* The class was seen in the current ZIP file and will be
1609 available as a compiled class in the future but may not have
1610 been loaded already. Load it if necessary. This prevent
1611 build_class_ref () from crashing. */
1613 if (seen_in_zip && !CLASS_LOADED_P (class))
1614 load_class (class, 1);
1616 /* We return 2 for class seen in ZIP and class from files
1617 belonging to the same compilation unit */
1621 if (assume_compiled (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (class)))))
1623 if (!CLASS_LOADED_P (class))
1625 if (CLASS_FROM_SOURCE_P (class))
1626 safe_layout_class (class);
1628 load_class (class, 1);
1636 /* Build a VAR_DECL for the dispatch table (vtable) for class TYPE. */
1639 build_dtable_decl (tree type)
1643 /* We need to build a new dtable type so that its size is uniquely
1644 computed when we're dealing with the class for real and not just
1645 faking it (like java.lang.Class during the initialization of the
1646 compiler.) We know we're not faking a class when CURRENT_CLASS is
1648 if (current_class == type)
1650 tree dummy = NULL_TREE;
1653 dtype = make_node (RECORD_TYPE);
1655 PUSH_FIELD (dtype, dummy, "top_offset", ptr_type_node);
1656 PUSH_FIELD (dtype, dummy, "type_info", ptr_type_node);
1658 PUSH_FIELD (dtype, dummy, "class", class_ptr_type);
1659 for (n = 1; n < TARGET_VTABLE_USES_DESCRIPTORS; ++n)
1661 tree tmp_field = build_decl (FIELD_DECL, NULL_TREE, ptr_type_node);
1662 TREE_CHAIN (dummy) = tmp_field;
1663 DECL_CONTEXT (tmp_field) = dtype;
1664 DECL_ARTIFICIAL (tmp_field) = 1;
1668 PUSH_FIELD (dtype, dummy, "gc_descr", ptr_type_node);
1669 for (n = 1; n < TARGET_VTABLE_USES_DESCRIPTORS; ++n)
1671 tree tmp_field = build_decl (FIELD_DECL, NULL_TREE, ptr_type_node);
1672 TREE_CHAIN (dummy) = tmp_field;
1673 DECL_CONTEXT (tmp_field) = dtype;
1674 DECL_ARTIFICIAL (tmp_field) = 1;
1678 n = TREE_VEC_LENGTH (get_dispatch_vector (type));
1679 if (TARGET_VTABLE_USES_DESCRIPTORS)
1680 n *= TARGET_VTABLE_USES_DESCRIPTORS;
1682 PUSH_FIELD (dtype, dummy, "methods",
1683 build_prim_array_type (nativecode_ptr_type_node, n));
1684 layout_type (dtype);
1687 dtype = dtable_type;
1689 return build_decl (VAR_DECL,
1690 java_mangle_vtable (&temporary_obstack, type), dtype);
1693 /* Pre-pend the TYPE_FIELDS of THIS_CLASS with a dummy FIELD_DECL for the
1694 fields inherited from SUPER_CLASS. */
1697 push_super_field (tree this_class, tree super_class)
1700 /* Don't insert the field if we're just re-laying the class out. */
1701 if (TYPE_FIELDS (this_class) && !DECL_NAME (TYPE_FIELDS (this_class)))
1703 base_decl = build_decl (FIELD_DECL, NULL_TREE, super_class);
1704 DECL_IGNORED_P (base_decl) = 1;
1705 TREE_CHAIN (base_decl) = TYPE_FIELDS (this_class);
1706 TYPE_FIELDS (this_class) = base_decl;
1707 DECL_SIZE (base_decl) = TYPE_SIZE (super_class);
1708 DECL_SIZE_UNIT (base_decl) = TYPE_SIZE_UNIT (super_class);
1711 /* Handle the different manners we may have to lay out a super class. */
1714 maybe_layout_super_class (tree super_class, tree this_class)
1716 if (TREE_CODE (super_class) == RECORD_TYPE)
1718 if (!CLASS_LOADED_P (super_class) && CLASS_FROM_SOURCE_P (super_class))
1719 safe_layout_class (super_class);
1720 if (!CLASS_LOADED_P (super_class))
1721 load_class (super_class, 1);
1723 /* We might have to layout the class before its dependency on
1724 the super class gets resolved by java_complete_class */
1725 else if (TREE_CODE (super_class) == POINTER_TYPE)
1727 if (TREE_TYPE (super_class) != NULL_TREE)
1728 super_class = TREE_TYPE (super_class);
1731 super_class = do_resolve_class (NULL_TREE, /* FIXME? */
1732 super_class, NULL_TREE, this_class);
1734 return NULL_TREE; /* FIXME, NULL_TREE not checked by caller. */
1735 super_class = TREE_TYPE (super_class);
1738 if (!TYPE_SIZE (super_class))
1739 safe_layout_class (super_class);
1745 layout_class (tree this_class)
1747 tree super_class = CLASSTYPE_SUPER (this_class);
1750 class_list = tree_cons (this_class, NULL_TREE, class_list);
1751 if (CLASS_BEING_LAIDOUT (this_class))
1757 sprintf (buffer, " with `%s'",
1758 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (this_class))));
1759 obstack_grow (&temporary_obstack, buffer, strlen (buffer));
1761 for (current = TREE_CHAIN (class_list); current;
1762 current = TREE_CHAIN (current))
1764 tree decl = TYPE_NAME (TREE_PURPOSE (current));
1765 sprintf (buffer, "\n which inherits from `%s' (%s:%d)",
1766 IDENTIFIER_POINTER (DECL_NAME (decl)),
1767 DECL_SOURCE_FILE (decl),
1768 DECL_SOURCE_LINE (decl));
1769 obstack_grow (&temporary_obstack, buffer, strlen (buffer));
1771 obstack_1grow (&temporary_obstack, '\0');
1772 report = obstack_finish (&temporary_obstack);
1773 cyclic_inheritance_report = ggc_strdup (report);
1774 obstack_free (&temporary_obstack, report);
1775 TYPE_SIZE (this_class) = error_mark_node;
1778 CLASS_BEING_LAIDOUT (this_class) = 1;
1780 if (super_class && !CLASS_BEING_LAIDOUT (super_class))
1782 tree maybe_super_class
1783 = maybe_layout_super_class (super_class, this_class);
1784 if (maybe_super_class == NULL
1785 || TREE_CODE (TYPE_SIZE (maybe_super_class)) == ERROR_MARK)
1787 TYPE_SIZE (this_class) = error_mark_node;
1788 CLASS_BEING_LAIDOUT (this_class) = 0;
1789 class_list = TREE_CHAIN (class_list);
1792 if (TYPE_SIZE (this_class) == NULL_TREE)
1793 push_super_field (this_class, maybe_super_class);
1796 for (field = TYPE_FIELDS (this_class);
1797 field != NULL_TREE; field = TREE_CHAIN (field))
1799 if (FIELD_STATIC (field))
1801 /* Set DECL_ASSEMBLER_NAME to something suitably mangled. */
1802 SET_DECL_ASSEMBLER_NAME (field,
1804 (&temporary_obstack, field));
1808 layout_type (this_class);
1810 /* Also recursively load/layout any superinterfaces, but only if class was
1811 loaded from bytecode. The source parser will take care of this itself. */
1812 if (!CLASS_FROM_SOURCE_P (this_class))
1814 tree basetype_vec = TYPE_BINFO_BASETYPES (this_class);
1818 int n = TREE_VEC_LENGTH (basetype_vec) - 1;
1820 for (i = n; i > 0; i--)
1822 tree vec_elt = TREE_VEC_ELT (basetype_vec, i);
1823 tree super_interface = BINFO_TYPE (vec_elt);
1825 tree maybe_super_interface
1826 = maybe_layout_super_class (super_interface, NULL_TREE);
1827 if (maybe_super_interface == NULL
1828 || TREE_CODE (TYPE_SIZE (maybe_super_interface)) == ERROR_MARK)
1830 TYPE_SIZE (this_class) = error_mark_node;
1831 CLASS_BEING_LAIDOUT (this_class) = 0;
1832 class_list = TREE_CHAIN (class_list);
1839 /* Convert the size back to an SI integer value */
1840 TYPE_SIZE_UNIT (this_class) =
1841 fold (convert (int_type_node, TYPE_SIZE_UNIT (this_class)));
1843 CLASS_BEING_LAIDOUT (this_class) = 0;
1844 class_list = TREE_CHAIN (class_list);
1848 layout_class_methods (tree this_class)
1850 tree method_decl, dtable_count;
1853 if (TYPE_NVIRTUALS (this_class))
1856 super_class = CLASSTYPE_SUPER (this_class);
1860 super_class = maybe_layout_super_class (super_class, this_class);
1861 if (!TYPE_NVIRTUALS (super_class))
1862 layout_class_methods (super_class);
1863 dtable_count = TYPE_NVIRTUALS (super_class);
1866 dtable_count = integer_zero_node;
1868 TYPE_METHODS (this_class) = nreverse (TYPE_METHODS (this_class));
1870 for (method_decl = TYPE_METHODS (this_class);
1871 method_decl; method_decl = TREE_CHAIN (method_decl))
1872 dtable_count = layout_class_method (this_class, super_class,
1873 method_decl, dtable_count);
1875 TYPE_NVIRTUALS (this_class) = dtable_count;
1878 /* Lay METHOD_DECL out, returning a possibly new value of
1879 DTABLE_COUNT. Also mangle the method's name. */
1882 layout_class_method (tree this_class, tree super_class,
1883 tree method_decl, tree dtable_count)
1885 tree method_name = DECL_NAME (method_decl);
1887 TREE_PUBLIC (method_decl) = 1;
1889 /* This is a good occasion to mangle the method's name */
1890 SET_DECL_ASSEMBLER_NAME (method_decl,
1891 java_mangle_decl (&temporary_obstack,
1893 /* We don't generate a RTL for the method if it's abstract, or if
1894 it's an interface method that isn't clinit. */
1895 if (! METHOD_ABSTRACT (method_decl)
1896 || (CLASS_INTERFACE (TYPE_NAME (this_class))
1897 && (DECL_CLINIT_P (method_decl))))
1898 make_decl_rtl (method_decl, NULL);
1900 if (ID_INIT_P (method_name))
1902 const char *p = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (this_class)));
1904 for (ptr = p; *ptr; )
1909 DECL_CONSTRUCTOR_P (method_decl) = 1;
1910 build_java_argument_signature (TREE_TYPE (method_decl));
1912 else if (! METHOD_STATIC (method_decl) && !DECL_ARTIFICIAL (method_decl))
1915 build_java_argument_signature (TREE_TYPE (method_decl));
1916 tree super_method = lookup_argument_method (super_class, method_name,
1918 if (super_method != NULL_TREE && ! METHOD_PRIVATE (super_method))
1920 DECL_VINDEX (method_decl) = DECL_VINDEX (super_method);
1921 if (DECL_VINDEX (method_decl) == NULL_TREE
1922 && !CLASS_FROM_SOURCE_P (this_class))
1923 error_with_decl (method_decl,
1924 "non-static method '%s' overrides static method");
1926 else if (! METHOD_FINAL (method_decl)
1927 && ! METHOD_PRIVATE (method_decl)
1928 && ! CLASS_FINAL (TYPE_NAME (this_class))
1931 DECL_VINDEX (method_decl) = dtable_count;
1932 dtable_count = fold (build (PLUS_EXPR, integer_type_node,
1933 dtable_count, integer_one_node));
1937 return dtable_count;
1941 register_class (void)
1943 /* END does not need to be registered with the garbage collector
1944 because it always points into the list given by REGISTERED_CLASS,
1945 and that variable is registered with the collector. */
1947 tree node = TREE_OPERAND (build_class_ref (current_class), 0);
1948 tree current = copy_node (node);
1950 XEXP (DECL_RTL (current), 0) = copy_rtx (XEXP (DECL_RTL(node), 0));
1951 if (!registered_class)
1952 registered_class = current;
1954 TREE_CHAIN (end) = current;
1959 /* Emit something to register classes at start-up time.
1961 The preferred mechanism is through the .jcr section, which contain
1962 a list of pointers to classes which get registered during
1963 constructor invocation time. The fallback mechanism is to generate
1964 a `constructor' function which calls _Jv_RegisterClass for each
1965 class in this file. */
1968 emit_register_classes (void)
1970 /* ??? This isn't quite the correct test. We also have to know
1971 that the target is using gcc's crtbegin/crtend objects rather
1972 than the ones that come with the operating system. */
1973 if (SUPPORTS_WEAK && targetm.have_named_sections)
1975 #ifdef JCR_SECTION_NAME
1977 named_section_flags (JCR_SECTION_NAME, SECTION_WRITE);
1978 assemble_align (POINTER_SIZE);
1979 for (t = registered_class; t; t = TREE_CHAIN (t))
1980 assemble_integer (XEXP (DECL_RTL (t), 0),
1981 POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1988 extern tree get_file_function_name (int);
1989 tree init_name = get_file_function_name ('I');
1990 tree init_type = build_function_type (void_type_node, end_params_node);
1994 init_decl = build_decl (FUNCTION_DECL, init_name, init_type);
1995 SET_DECL_ASSEMBLER_NAME (init_decl, init_name);
1996 TREE_STATIC (init_decl) = 1;
1997 current_function_decl = init_decl;
1998 DECL_RESULT (init_decl) = build_decl (RESULT_DECL, NULL_TREE,
2001 /* It can be a static function as long as collect2 does not have
2002 to scan the object file to find its ctor/dtor routine. */
2003 TREE_PUBLIC (init_decl) = ! targetm.have_ctors_dtors;
2005 /* Suppress spurious warnings. */
2006 TREE_USED (init_decl) = 1;
2009 make_decl_rtl (init_decl, NULL);
2010 init_function_start (init_decl, input_filename, 0);
2011 expand_function_start (init_decl, 0);
2013 /* Do not allow the function to be deferred. */
2014 current_function_cannot_inline
2015 = "static constructors and destructors cannot be inlined";
2017 for ( t = registered_class; t; t = TREE_CHAIN (t))
2018 emit_library_call (registerClass_libfunc, 0, VOIDmode, 1,
2019 XEXP (DECL_RTL (t), 0), Pmode);
2021 expand_function_end (input_filename, 0, 0);
2023 rest_of_compilation (init_decl);
2024 current_function_decl = NULL_TREE;
2026 if (targetm.have_ctors_dtors)
2027 (* targetm.asm_out.constructor) (XEXP (DECL_RTL (init_decl), 0),
2028 DEFAULT_INIT_PRIORITY);
2032 /* Make a method_symbol_type (_Jv_MethodSymbol) node for METHOD. */
2035 build_method_symbols_entry (tree method)
2037 tree clname, name, signature, method_symbol;
2039 clname = build_utf8_ref (DECL_NAME (TYPE_NAME (DECL_CONTEXT (method))));
2040 name = build_utf8_ref (DECL_NAME (method));
2041 signature = build_java_signature (TREE_TYPE (method));
2042 signature = build_utf8_ref (unmangle_classname
2043 (IDENTIFIER_POINTER (signature),
2044 IDENTIFIER_LENGTH (signature)));
2046 START_RECORD_CONSTRUCTOR (method_symbol, method_symbol_type);
2047 PUSH_FIELD_VALUE (method_symbol, "clname", clname);
2048 PUSH_FIELD_VALUE (method_symbol, "name", name);
2049 PUSH_FIELD_VALUE (method_symbol, "signature", signature);
2050 FINISH_RECORD_CONSTRUCTOR (method_symbol);
2051 TREE_CONSTANT (method_symbol) = 1;
2053 return method_symbol;
2056 /* Emit the offset symbols table for indirect virtual dispatch. */
2059 emit_offset_symbol_table (void)
2061 tree method_list, method, table, list, null_symbol;
2062 tree otable_bound, otable_array_type;
2065 /* Only emit an offset table if this translation unit actually made virtual
2067 if (otable_methods == NULL_TREE)
2070 /* Build a list of _Jv_MethodSymbols for each entry in otable_methods. */
2072 method_list = otable_methods;
2074 while (method_list != NULL_TREE)
2076 method = TREE_VALUE (method_list);
2077 list = tree_cons (NULL_TREE, build_method_symbols_entry (method), list);
2078 method_list = TREE_CHAIN (method_list);
2082 /* Terminate the list with a "null" entry. */
2083 START_RECORD_CONSTRUCTOR (null_symbol, method_symbol_type);
2084 PUSH_FIELD_VALUE (null_symbol, "clname", null_pointer_node);
2085 PUSH_FIELD_VALUE (null_symbol, "name", null_pointer_node);
2086 PUSH_FIELD_VALUE (null_symbol, "signature", null_pointer_node);
2087 FINISH_RECORD_CONSTRUCTOR (null_symbol);
2088 TREE_CONSTANT (null_symbol) = 1;
2089 list = tree_cons (NULL_TREE, null_symbol, list);
2091 /* Put the list in the right order and make it a constructor. */
2092 list = nreverse (list);
2093 table = build (CONSTRUCTOR, method_symbols_array_type, NULL_TREE, list);
2095 /* Make it the initial value for otable_syms and emit the decl. */
2096 DECL_INITIAL (otable_syms_decl) = table;
2097 DECL_ARTIFICIAL (otable_syms_decl) = 1;
2098 DECL_IGNORED_P (otable_syms_decl) = 1;
2099 rest_of_decl_compilation (otable_syms_decl, NULL, 1, 0);
2101 /* Now that its size is known, redefine otable as an uninitialized static
2102 array of INDEX + 1 integers. The extra entry is used by the runtime
2103 to track whether the otable has been initialized. */
2104 otable_bound = build_index_type (build_int_2 (index, 0));
2105 otable_array_type = build_array_type (integer_type_node, otable_bound);
2106 otable_decl = build_decl (VAR_DECL, get_identifier ("otable"),
2108 TREE_STATIC (otable_decl) = 1;
2109 TREE_READONLY (otable_decl) = 1;
2110 rest_of_decl_compilation (otable_decl, NULL, 1, 0);
2114 init_class_processing (void)
2116 registerClass_libfunc = gen_rtx_SYMBOL_REF (Pmode, "_Jv_RegisterClass");
2117 fields_ident = get_identifier ("fields");
2118 info_ident = get_identifier ("info");
2119 gcc_obstack_init (&temporary_obstack);
2122 static hashval_t java_treetreehash_hash (const void *);
2123 static int java_treetreehash_compare (const void *, const void *);
2125 /* A hash table mapping trees to trees. Used generally. */
2127 #define JAVA_TREEHASHHASH_H(t) (htab_hash_pointer (t))
2130 java_treetreehash_hash (const void *k_p)
2132 struct treetreehash_entry *k = (struct treetreehash_entry *) k_p;
2133 return JAVA_TREEHASHHASH_H (k->key);
2137 java_treetreehash_compare (const void * k1_p, const void * k2_p)
2139 struct treetreehash_entry * k1 = (struct treetreehash_entry *) k1_p;
2140 tree k2 = (tree) k2_p;
2141 return (k1->key == k2);
2145 java_treetreehash_find (htab_t ht, tree t)
2147 struct treetreehash_entry *e;
2148 hashval_t hv = JAVA_TREEHASHHASH_H (t);
2149 e = (struct treetreehash_entry *) htab_find_with_hash (ht, t, hv);
2157 java_treetreehash_new (htab_t ht, tree t)
2160 struct treetreehash_entry *tthe;
2161 hashval_t hv = JAVA_TREEHASHHASH_H (t);
2163 e = htab_find_slot_with_hash (ht, t, hv, INSERT);
2166 tthe = (*ht->alloc_f) (1, sizeof (*tthe));
2171 tthe = (struct treetreehash_entry *) *e;
2172 return &tthe->value;
2176 java_treetreehash_create (size_t size, int gc)
2179 return htab_create_ggc (size, java_treetreehash_hash,
2180 java_treetreehash_compare, NULL);
2182 return htab_create_alloc (size, java_treetreehash_hash,
2183 java_treetreehash_compare, free, xcalloc, free);
2186 #include "gt-java-class.h"