diff options
author | Bryce McKinlay <bryce@waitaki.otago.ac.nz> | 2001-12-15 08:31:49 +0000 |
---|---|---|
committer | Bryce McKinlay <bryce@gcc.gnu.org> | 2001-12-15 08:31:49 +0000 |
commit | 861ef92859ce3681ae24ecac1384e0be2a035c9d (patch) | |
tree | a15d17366ad109cb78a0bc4f4aaf8e142550387d /gcc/java/expr.c | |
parent | ed86a83d510ad44be77328cf80b1e6198f992c7c (diff) | |
download | gcc-861ef92859ce3681ae24ecac1384e0be2a035c9d.zip gcc-861ef92859ce3681ae24ecac1384e0be2a035c9d.tar.gz gcc-861ef92859ce3681ae24ecac1384e0be2a035c9d.tar.bz2 |
java-tree.h (otable_methods, [...]): New field/global tree definitions.
gcc/java:
* java-tree.h (otable_methods, otable_decl, otable_syms_decl,
otable_type, otable_ptr_type, method_symbol_type,
method_symbols_array_type, method_symbols_array_ptr_type): New
field/global tree definitions.
(flag_indirect_dispatch): New flag.
* decl.c (java_init_decl_processing): Initialize new otable and
otable_syms type nodes and decls. Add new field "index" to
method_type_node.
* class.c (build_method_symbols_entry): New function.
(make_method_value): Set "index" to to method's vtable index for
virtual methods when indirect-dispatch is not used.
(make_class_data): For indirect-dispatch, dont emit the dtable_decl,
and set vtable_method_count to -1. Set otable and otable_syms field
if indirect-dispatch is used and there was something to put in them.
(build_method_symbols_entry): New function.
(emit_offset_symbol_table): New function.
* expr.c (get_offset_table_index): New function.
(build_invokevirtual): Build array reference to otable at the index
returned by get_offset_table_index, and use the result as the vtable
offset.
(build_invokeinterface): Similar.
* jcf-parse.c (yyparse): If indirect-dispatch, call
emit_offset_symbol_table at the end of compilation, after all classes
have been generated.
* jvspec.c: Don't pass findirect-dispatch to jvgenmain.
* lang.c (flag_indirect_dispatch): Define.
(lang_f_options): Add indirect-dispatch flag.
libjava:
* include/jvm.h (_Jv_VTable::idx_to_offset): New method.
* java/lang/natClassLoader.cc (_Jv_PrepareCompiledClass): Call
_Jv_MakeVTable and _Jv_LinkOffsetTable if needed.
* java/lang/Class.h (_Jv_Method): Add "index" field.
(_Jv_MethodSymbol): New struct type.
(_Jv_LinkOffsetTable, _Jv_LayoutVTableMethods, _Jv_SetVTableEntries,
_Jv_MakeVTable): Friends.
(otable, otable_syms): New Class fields.
* java/lang/natClass.cc (_Jv_LinkOffsetTable): New function.
(isVirtualMethod): New static function.
(_Jv_LayoutVTableMethods): New function.
(_Jv_SetVTableEntries): New function.
(_Jv_MakeVTable): New function.
From-SVN: r48038
Diffstat (limited to 'gcc/java/expr.c')
-rw-r--r-- | gcc/java/expr.c | 95 |
1 files changed, 76 insertions, 19 deletions
diff --git a/gcc/java/expr.c b/gcc/java/expr.c index ef1a139..e5d141e 100644 --- a/gcc/java/expr.c +++ b/gcc/java/expr.c @@ -84,6 +84,7 @@ static tree case_identity PARAMS ((tree, tree)); static unsigned char peek_opcode_at_pc PARAMS ((struct JCF *, int, int)); static bool emit_init_test_initialization PARAMS ((struct hash_entry *, PTR ptr)); +static int get_offset_table_index PARAMS ((tree)); static tree operand_type[59]; extern struct obstack permanent_obstack; @@ -1856,6 +1857,40 @@ invoke_build_dtable (is_invoke_interface, arg_list) return dtable; } +/* Determine the index in the virtual offset table (otable) for a call to + METHOD. If this method has not been seen before, it will be added to the + otable_methods. If it has, the existing otable slot will be reused. */ + +int +get_offset_table_index (method) + tree method; +{ + int i = 1; + tree method_list; + + if (otable_methods == NULL_TREE) + { + otable_methods = build_tree_list (method, method); + return 1; + } + + method_list = otable_methods; + + while (1) + { + if (TREE_VALUE (method_list) == method) + return i; + i++; + if (TREE_CHAIN (method_list) == NULL_TREE) + break; + else + method_list = TREE_CHAIN (method_list); + } + + TREE_CHAIN (method_list) = build_tree_list (method, method); + return i; +} + tree build_invokevirtual (dtable, method) tree dtable, method; @@ -1863,20 +1898,33 @@ build_invokevirtual (dtable, method) tree func; tree nativecode_ptr_ptr_type_node = build_pointer_type (nativecode_ptr_type_node); - tree method_index = convert (sizetype, DECL_VINDEX (method)); + tree method_index; + tree otable_index; - if (TARGET_VTABLE_USES_DESCRIPTORS) - /* Add one to skip bogus descriptor for class and GC descriptor. */ - method_index = size_binop (PLUS_EXPR, method_index, size_int (1)); + if (flag_indirect_dispatch) + { + otable_index = build_int_2 (get_offset_table_index (method), 0); + method_index = build (ARRAY_REF, integer_type_node, otable_decl, + otable_index); + } else - /* Add 1 to skip "class" field of dtable, and 1 to skip GC descriptor. */ - method_index = size_binop (PLUS_EXPR, method_index, size_int (2)); - method_index = size_binop (MULT_EXPR, method_index, - TYPE_SIZE_UNIT (nativecode_ptr_ptr_type_node)); + { + method_index = convert (sizetype, DECL_VINDEX (method)); - if (TARGET_VTABLE_USES_DESCRIPTORS) - method_index = size_binop (MULT_EXPR, method_index, - size_int (TARGET_VTABLE_USES_DESCRIPTORS)); + if (TARGET_VTABLE_USES_DESCRIPTORS) + /* Add one to skip bogus descriptor for class and GC descriptor. */ + method_index = size_binop (PLUS_EXPR, method_index, size_int (1)); + else + /* Add 1 to skip "class" field of dtable, and 1 to skip GC descriptor. */ + method_index = size_binop (PLUS_EXPR, method_index, size_int (2)); + + method_index = size_binop (MULT_EXPR, method_index, + TYPE_SIZE_UNIT (nativecode_ptr_ptr_type_node)); + + if (TARGET_VTABLE_USES_DESCRIPTORS) + method_index = size_binop (MULT_EXPR, method_index, + size_int (TARGET_VTABLE_USES_DESCRIPTORS)); + } func = fold (build (PLUS_EXPR, nativecode_ptr_ptr_type_node, dtable, convert (nativecode_ptr_ptr_type_node, method_index))); @@ -1898,6 +1946,7 @@ build_invokeinterface (dtable, method) tree interface; tree idx; tree meth; + tree otable_index; int i; /* We expand invokeinterface here. _Jv_LookupInterfaceMethod() will @@ -1917,16 +1966,24 @@ build_invokeinterface (dtable, method) interface = DECL_CONTEXT (method); layout_class_methods (interface); - i = 1; - for (meth = TYPE_METHODS (interface); ; meth = TREE_CHAIN (meth), i++) + if (flag_indirect_dispatch) { - if (meth == method) - { - idx = build_int_2 (i, 0); - break; + otable_index = build_int_2 (get_offset_table_index (method), 0); + idx = build (ARRAY_REF, integer_type_node, otable_decl, otable_index); + } + else + { + i = 1; + for (meth = TYPE_METHODS (interface); ; meth = TREE_CHAIN (meth), i++) + { + if (meth == method) + { + idx = build_int_2 (i, 0); + break; + } + if (meth == NULL_TREE) + abort (); } - if (meth == NULL_TREE) - abort (); } lookup_arg = tree_cons (NULL_TREE, dtable, |