class initialization check overhead
shudo@computer.org
shudo@computer.org
Wed Oct 30 06:49:00 GMT 2002
Jeff Sturm wrote:
> I have many patches lumped together at the moment.
> Soon I'll have to see which are suitable for submission.
Your patch modifies gcc/java/builtins.c, and then GCJ eliminates
invocation of the constructor of java.lang.Object.
But, invocation of the constructor has to throw a NullPointerException
if the reference on which the constructor is called.
I attach a test code named OmitObjectInitTest.class to this mail.
It calls the constructor on a null reference:
| Method void main(java.lang.String[])
| 0 aconst_null
| 1 astore_1
| 2 aload_1
| 3 invokespecial #3 <Method java.lang.Object()>
| 6 return
As you might notice, Any Java compiler does not generate this bytecode.
I modified OmitObjectInitTest.class generated by a Java compiler.
Sun's Java 2 SE 1.4.1 throws java.lang.VeifyError and
JDK 1.1.8 throws NullPointerException.
GCJ 3.2 (Sep 2002) does nothing.
I believe a JVM should throw NullPointerException if the JVM can
execute bytecode without verification.
> Try this:
>
> Index: builtins.c
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/java/builtins.c,v
> retrieving revision 1.10
> diff -u -p -r1.10 builtins.c
> --- builtins.c 11 Jul 2002 01:20:22 -0000 1.10
> +++ builtins.c 25 Oct 2002 12:39:39 -0000
> @@ -65,6 +65,7 @@ static tree abs_builtin PARAMS ((tree, t
> static tree cos_builtin PARAMS ((tree, tree));
> static tree sin_builtin PARAMS ((tree, tree));
> static tree sqrt_builtin PARAMS ((tree, tree));
> +static tree init_builtin PARAMS ((tree, tree));
>
> static tree build_function_call_expr PARAMS ((tree, tree));
> static void define_builtin PARAMS ((enum built_in_function,
> @@ -105,6 +106,7 @@ static GTY(()) struct builtin_record jav
> { { "java.lang.Math" }, { "cos" }, cos_builtin },
> { { "java.lang.Math" }, { "sin" }, sin_builtin },
> { { "java.lang.Math" }, { "sqrt" }, sqrt_builtin },
> + { { "java.lang.Object" }, { "<init>" }, init_builtin },
> { { NULL }, { NULL }, NULL }
> };
>
> @@ -185,6 +187,13 @@ sqrt_builtin (method_return_type, method
> if (fn == NULL_TREE)
> return NULL_TREE;
> return build_function_call_expr (fn, method_arguments);
> +}
> +
> +static tree
> +init_builtin (method_return_type, method_arguments)
> + tree method_return_type ATTRIBUTE_UNUSED, method_arguments;
> +{
> + return empty_stmt_node;
> }
Kazuyuki Shudo shudo@computer.org http://www.shudo.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OmitObjectInitTest.class
Type: application/octet-stream
Size: 399 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java/attachments/20021030/5f355771/attachment.class>
More information about the Java
mailing list