GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING. If not, write to
-the Free Software Foundation, 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
static GTY(()) VEC(tree,gc) *registered_class;
+/* A tree that returns the address of the class$ of the class
+ currently being compiled. */
+static GTY(()) tree this_classdollar;
+
/* Return the node that most closely represents the class whose name
is IDENT. Start the search from NODE (followed by its siblings).
Return NULL if an appropriate node does not exist. */
tree decl, signature;
location_t saved_loc = input_location;
#ifndef USE_MAPPED_LOCATION
- tree source_name = identifier_subst (class_name, "", '.', '/', ".java");
- input_filename = IDENTIFIER_POINTER (source_name);
+ input_filename = "<unknown>";
input_line = 0;
#endif
CLASS_P (class_type) = 1;
return fntype;
}
+static void
+hide (tree decl ATTRIBUTE_UNUSED)
+{
+#ifdef HAVE_GAS_HIDDEN
+ DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
+ DECL_VISIBILITY_SPECIFIED (decl) = 1;
+#endif
+}
+
tree
add_method_1 (tree this_class, int access_flags, tree name, tree function_type)
{
TREE_CHAIN (fndecl) = TYPE_METHODS (this_class);
TYPE_METHODS (this_class) = fndecl;
+ /* If pointers to member functions use the least significant bit to
+ indicate whether a function is virtual, ensure a pointer
+ to this function will have that bit clear. */
+ if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_pfn
+ && !(access_flags & ACC_STATIC)
+ && DECL_ALIGN (fndecl) < 2 * BITS_PER_UNIT)
+ DECL_ALIGN (fndecl) = 2 * BITS_PER_UNIT;
+
/* Notice that this is a finalizer and update the class type
accordingly. This is used to optimize instance allocation. */
if (name == finalize_identifier_node
/* Always make field externally visible. This is required so
that native methods can always access the field. */
TREE_PUBLIC (field) = 1;
+ /* Hide everything that shouldn't be visible outside a DSO. */
+ if (flag_indirect_classes
+ || (FIELD_PRIVATE (field)))
+ hide (field);
/* Considered external unless we are compiling it into this
object file. */
DECL_EXTERNAL (field) = (is_compiled_class (class) != 2);
&& TREE_TYPE (field) == string_ptr_type_node))
error ("ConstantValue attribute of field '%s' has wrong type",
IDENTIFIER_POINTER (DECL_NAME (field)));
- if (FIELD_FINAL (field))
- DECL_FIELD_FINAL_IUD (field) = 1;
}
}
decl = build_decl (VAR_DECL, decl_name, class_type_node);
TREE_STATIC (decl) = 1;
if (! flag_indirect_classes)
- TREE_PUBLIC (decl) = 1;
+ {
+ TREE_PUBLIC (decl) = 1;
+ if (CLASS_PRIVATE (TYPE_NAME (type)))
+ hide (decl);
+ }
DECL_IGNORED_P (decl) = 1;
DECL_ARTIFICIAL (decl) = 1;
if (is_compiled_class (type) == 1)
TREE_CONSTANT (decl) = 1;
TREE_READONLY (decl) = 1;
TREE_PUBLIC (decl) = 1;
+ hide (decl);
DECL_IGNORED_P (decl) = 1;
DECL_ARTIFICIAL (decl) = 1;
MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
return decl;
}
+/* Create a local variable that holds the current class$. */
+
+void
+cache_this_class_ref (tree fndecl)
+{
+ if (optimize)
+ {
+ tree classdollar_field;
+ if (flag_indirect_classes)
+ classdollar_field = build_classdollar_field (output_class);
+ else
+ classdollar_field = build_static_class_ref (output_class);
+
+ this_classdollar = build_decl (VAR_DECL, NULL_TREE,
+ TREE_TYPE (classdollar_field));
+
+ java_add_local_var (this_classdollar);
+ java_add_stmt (build2 (MODIFY_EXPR, TREE_TYPE (this_classdollar),
+ this_classdollar, classdollar_field));
+ }
+ else
+ this_classdollar = build_classdollar_field (output_class);
+
+ /* Prepend class initialization for static methods reachable from
+ other classes. */
+ if (METHOD_STATIC (fndecl)
+ && (! METHOD_PRIVATE (fndecl)
+ || INNER_CLASS_P (DECL_CONTEXT (fndecl)))
+ && ! DECL_CLINIT_P (fndecl)
+ && ! CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (fndecl))))
+ {
+ tree init = build_call_expr (soft_initclass_node, 1,
+ this_classdollar);
+ java_add_stmt (init);
+ }
+}
+
+/* Remove the reference to the local variable that holds the current
+ class$. */
+
+void
+uncache_this_class_ref (tree fndecl ATTRIBUTE_UNUSED)
+{
+ this_classdollar = build_classdollar_field (output_class);
+}
+
/* Build a reference to the class TYPE.
Also handles primitive types and array types. */
return build_indirect_class_ref (type);
if (type == output_class && flag_indirect_classes)
- return build_classdollar_field (type);
+ return this_classdollar;
if (TREE_CODE (type) == RECORD_TYPE)
return build_static_class_ref (type);
{
tree fclass = DECL_CONTEXT (fdecl);
int is_compiled = is_compiled_class (fclass);
- int from_class = ! CLASS_FROM_SOURCE_P (current_class);
/* Allow static final fields to fold to a constant. When using
-findirect-dispatch, we simply never do this folding if compiling
from .class; in the .class file constants will be referred to via
the constant pool. */
- if ((!flag_indirect_dispatch || !from_class)
+ if (!flag_indirect_dispatch
&& (is_compiled
|| (FIELD_FINAL (fdecl) && DECL_INITIAL (fdecl) != NULL_TREE
&& (JSTRING_TYPE_P (TREE_TYPE (fdecl))
int cpool_index = alloc_constant_fieldref (output_class, fdecl);
tree cache_entry = build_fieldref_cache_entry (cpool_index, fdecl);
- tree test
- = build3 (CALL_EXPR, boolean_type_node,
- build_address_of (built_in_decls[BUILT_IN_EXPECT]),
- tree_cons (NULL_TREE, build2 (EQ_EXPR, boolean_type_node,
- cache_entry, null_pointer_node),
- build_tree_list (NULL_TREE, boolean_false_node)),
- NULL_TREE);
+ tree test
+ = build_call_expr (built_in_decls[BUILT_IN_EXPECT], 2,
+ build2 (EQ_EXPR, boolean_type_node,
+ cache_entry, null_pointer_node),
+ boolean_false_node);
tree cpool_index_cst = build_int_cst (NULL_TREE, cpool_index);
tree init
- = build3 (CALL_EXPR, ptr_type_node,
- build_address_of (soft_resolvepoolentry_node),
- tree_cons (NULL_TREE, build_class_ref (output_class),
- build_tree_list (NULL_TREE, cpool_index_cst)),
- NULL_TREE);
+ = build_call_expr (soft_resolvepoolentry_node, 2,
+ build_class_ref (output_class),
+ cpool_index_cst);
init = build2 (MODIFY_EXPR, ptr_type_node, cache_entry, init);
init = build3 (COND_EXPR, ptr_type_node, test, init, cache_entry);
init = fold_convert (build_pointer_type (TREE_TYPE (fdecl)), init);
tree id_class = get_identifier("java.lang.Class");
/** Offset from start of virtual function table declaration
to where objects actually point at, following new g++ ABI. */
- tree dtable_start_offset = build_int_cst (NULL_TREE,
- 2 * POINTER_SIZE / BITS_PER_UNIT);
+ tree dtable_start_offset = size_int (2 * POINTER_SIZE / BITS_PER_UNIT);
VEC(int, heap) *field_indexes;
tree first_real_field;
TREE_PUBLIC (dtable_decl) = 1;
DECL_INITIAL (dtable_decl) = dtable;
+ /* The only dispatch table exported from a DSO is the dispatch
+ table for java.lang.Class. */
+ if (DECL_NAME (type_decl) != id_class)
+ hide (dtable_decl);
if (! flag_indirect_classes)
rest_of_decl_compilation (dtable_decl, 1, 0);
/* Maybe we're compiling Class as the first class. If so, set
|| DECL_CLINIT_P (method)
|| DECL_NAME (type_decl) == id_class
|| DECL_NAME (method) == id_main
- || (METHOD_PUBLIC (method) && !METHOD_STATIC (method))
- || TYPE_DOT_CLASS (type) == method)
+ || (METHOD_PUBLIC (method) && !METHOD_STATIC (method)))
{
init = make_method_value (method);
method_count++;
PUSH_FIELD_VALUE (temp, "vtable",
(flag_indirect_classes
? null_pointer_node
- : build2 (PLUS_EXPR, dtable_ptr_type,
+ : build2 (POINTER_PLUS_EXPR, dtable_ptr_type,
build1 (ADDR_EXPR, dtable_ptr_type,
class_dtable_decl),
dtable_start_offset)));
else
PUSH_FIELD_VALUE (cons, "vtable",
dtable_decl == NULL_TREE ? null_pointer_node
- : build2 (PLUS_EXPR, dtable_ptr_type,
+ : build2 (POINTER_PLUS_EXPR, dtable_ptr_type,
build1 (ADDR_EXPR, dtable_ptr_type,
dtable_decl),
dtable_start_offset));
void
finish_class (void)
{
- if (TYPE_VERIFY_METHOD (output_class))
- {
- tree verify_method = TYPE_VERIFY_METHOD (output_class);
- DECL_SAVED_TREE (verify_method)
- = add_stmt_to_compound (DECL_SAVED_TREE (verify_method), void_type_node,
- build1 (RETURN_EXPR, void_type_node, NULL));
- java_genericize (verify_method);
- cgraph_finalize_function (verify_method, false);
- TYPE_ASSERTIONS (current_class) = NULL;
- }
-
java_expand_catch_classes (current_class);
current_function_decl = NULL_TREE;
{
if (!CLASS_LOADED_P (class))
{
- if (CLASS_FROM_SOURCE_P (class))
- safe_layout_class (class);
- else if (class != current_class)
+ if (class != current_class)
load_class (class, 1);
}
return 1;
return NULL_TREE;
else if (TREE_CODE (super_class) == RECORD_TYPE)
{
- if (!CLASS_LOADED_P (super_class) && CLASS_FROM_SOURCE_P (super_class))
- safe_layout_class (super_class);
if (!CLASS_LOADED_P (super_class))
load_class (super_class, 1);
}
void
layout_class (tree this_class)
{
+ int i;
tree super_class = CLASSTYPE_SUPER (this_class);
class_list = tree_cons (this_class, NULL_TREE, class_list);
layout_type (this_class);
- /* Also recursively load/layout any superinterfaces, but only if
- class was loaded from bytecode. The source parser will take care
- of this itself. */
- if (!CLASS_FROM_SOURCE_P (this_class))
+ /* Also recursively load/layout any superinterfaces. */
+ if (TYPE_BINFO (this_class))
{
- int i;
- if (TYPE_BINFO (this_class))
+ for (i = BINFO_N_BASE_BINFOS (TYPE_BINFO (this_class)) - 1; i > 0; i--)
{
- for (i = BINFO_N_BASE_BINFOS (TYPE_BINFO (this_class)) - 1; i > 0; i--)
+ tree binfo = BINFO_BASE_BINFO (TYPE_BINFO (this_class), i);
+ tree super_interface = BINFO_TYPE (binfo);
+ tree maybe_super_interface
+ = maybe_layout_super_class (super_interface, NULL_TREE);
+ if (maybe_super_interface == NULL
+ || TREE_CODE (TYPE_SIZE (maybe_super_interface)) == ERROR_MARK)
{
- tree binfo = BINFO_BASE_BINFO (TYPE_BINFO (this_class), i);
- tree super_interface = BINFO_TYPE (binfo);
- tree maybe_super_interface
- = maybe_layout_super_class (super_interface, NULL_TREE);
- if (maybe_super_interface == NULL
- || TREE_CODE (TYPE_SIZE (maybe_super_interface)) == ERROR_MARK)
- {
- TYPE_SIZE (this_class) = error_mark_node;
- CLASS_BEING_LAIDOUT (this_class) = 0;
- class_list = TREE_CHAIN (class_list);
- return;
- }
+ TYPE_SIZE (this_class) = error_mark_node;
+ CLASS_BEING_LAIDOUT (this_class) = 0;
+ class_list = TREE_CHAIN (class_list);
+ return;
}
}
}
if (TYPE_NVIRTUALS (this_class))
return;
-
+
super_class = CLASSTYPE_SUPER (this_class);
if (super_class)
TREE_PUBLIC (method_decl) = 1;
+ if (flag_indirect_classes
+ || (METHOD_PRIVATE (method_decl) && METHOD_STATIC (method_decl)
+ && ! METHOD_NATIVE (method_decl)
+ && ! special_method_p (method_decl)))
+ hide (method_decl);
+
/* Considered external unless it is being compiled into this object
file, or it was already flagged as external. */
if (!DECL_EXTERNAL (method_decl))
set_method_index (method_decl, method_index);
if (method_index == NULL_TREE
&& ! flag_indirect_dispatch
- && !CLASS_FROM_SOURCE_P (this_class)
&& ! DECL_ARTIFICIAL (super_method))
error ("non-static method %q+D overrides static method",
method_decl);
TREE_PUBLIC (t) = 1;
DECL_EXTERNAL (t) = 1;
register_class_fn = t;
- t = tree_cons (NULL, reg_class_list, NULL);
- t = build_function_call_expr (register_class_fn, t);
+ t = build_call_expr (register_class_fn, 1, reg_class_list);
append_to_statement_list (t, list_p);
}
for (i = 0; VEC_iterate (tree, registered_class, i, klass); ++i)
{
t = build_fold_addr_expr (klass);
- t = tree_cons (NULL, t, NULL);
- t = build_function_call_expr (register_class_fn, t);
+ t = build_call_expr (register_class_fn, 1, t);
append_to_statement_list (t, list_p);
}
}
system that this is a "special" symbol, i.e. one that should
bypass access controls. */
if (special != NULL_TREE)
- signature = build2 (PLUS_EXPR, TREE_TYPE (signature), signature, special);
+ signature = build2 (POINTER_PLUS_EXPR, TREE_TYPE (signature), signature,
+ fold_convert (sizetype, special));
START_RECORD_CONSTRUCTOR (sym, symbol_type);
PUSH_FIELD_VALUE (sym, "clname", clname);
static hashval_t
java_treetreehash_hash (const void *k_p)
{
- struct treetreehash_entry *k = (struct treetreehash_entry *) k_p;
+ const struct treetreehash_entry *const k
+ = (const struct treetreehash_entry *) k_p;
return JAVA_TREEHASHHASH_H (k->key);
}
static int
java_treetreehash_compare (const void * k1_p, const void * k2_p)
{
- struct treetreehash_entry * k1 = (struct treetreehash_entry *) k1_p;
- tree k2 = (tree) k2_p;
+ const struct treetreehash_entry *const k1
+ = (const struct treetreehash_entry *) k1_p;
+ const_tree const k2 = (const_tree) k2_p;
return (k1->key == k2);
}