Fibonacci and performance
Anthony Green
green@redhat.com
Sat Apr 28 08:24:00 GMT 2001
Hans wrote:
> Perhaps it makes sense to inline the class initialization test as
>> static volatile bool I_already_initialized_this_class_from_this_file;
> /* The volatile declaration should suffice to make this thread-safe
> on X86 and IA64. */
> /* The current code already looks dubious to me for something like
> Alpha. */
>> if (!I_already_initialized_this_class_from_this_file) {
> _Jv_InitClass(...); // Checks whether someone else
> initialized it.
> I_already_initialized_this_class_from_this_file = true;
> }
This is very similar to how we currently deal with class initialization for
static variable references. So most of the infrastructure already exists
(ChangeLog entry appended).
One difference is that the class initialization flag in my change is a
method local, not file static as you suggest. The advantage is that the
compiler will automagically optimize out redundant _Jv_InitClass calls in a
given method. I don't think this will happen if we use a volatile file
static. Perhaps combining the two techniques would work well.
AG
2000年02月25日 Anthony Green <green@cygnus.com>
* expr.c (build_class_init): Mark the decl to be ignored by
check_init.
* java-tree.h (DECL_BIT_INDEX): Move definition from check-init.c
* check-init.c: Move DECL_BIT_INDEX to java-tree.h
* class.c (init_test_hash_newfunc): New function.
(decl_hash): New function.
(decl_compare): New function.
* decl.c (emit_init_test_initialization): New function.
(complete_start_java_method): Traverse the init test hashtable,
calling emit_init_test_initialization.
(always_initialize_class_p): Define.
* expr.c (build_class_init): Use initialization tests when
emitting class initialization code.
(always_initialize_class_p): Declare.
* jcf-parse.c (parse_class_file): Set always_initialize_class_p to
1.
* java-tree.h: Include hash.h.
(DECL_FUNCTION_INIT_TEST_TABLE): Define.
(struct lang_decl): Add init_test_table field.
(init_test_hash_entry): Define.
More information about the Java
mailing list