Patch: gcj -fjni fix
Tom Tromey
tromey@redhat.com
Thu Jan 24 21:57:00 GMT 2002
While debugging some JNI code, I noticed that occasionally the storage
for the cached JNI method pointer was not allocated. This resulted in
hard-to-debug crashes in JNI code at runtime. Weirdly, this didn't
always happen.
This patch fixes the problem for me. I'm not certain it is really
correct.
I stopped using pushdecl_top_level, since we really haven't set up the
global state to call that function. Instead I put the new variable
into the list local to the method, and explicitly call layout_decl and
rest_of_decl_compilation.
The parse.y change isn't strictly necessary. It is a remnant of an
earlier attempt at a fix. However, it is correct and clarified things
a bit for me.
Is this ok? If not, what is the correct thing to do in build_jni_stub?
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* expr.c (build_jni_stub): Ensure storage for `meth' is
generated.
* parse.y (java_complete_expand_methods): Set
current_function_decl before building JNI stub.
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.128
diff -u -r1.128 expr.c
--- expr.c 2002/01/22 20:23:45 1.128
+++ expr.c 2002/01/25 05:35:50
@@ -2168,8 +2168,13 @@
TREE_PUBLIC (meth_var) = 0;
DECL_EXTERNAL (meth_var) = 0;
DECL_CONTEXT (meth_var) = method;
+ DECL_ARTIFICIAL (meth_var) = 1;
+ DECL_INITIAL (meth_var) = null_pointer_node;
+ TREE_USED (meth_var) = 1;
+ chainon (env_var, meth_var);
+ layout_decl (meth_var, 0);
make_decl_rtl (meth_var, NULL);
- meth_var = pushdecl_top_level (meth_var);
+ rest_of_decl_compilation (meth_var, NULL, 0, 0);
/* One strange way that the front ends are different is that they
store arguments differently. */
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.345
diff -u -r1.345 parse.y
--- parse.y 2002/01/22 20:23:46 1.345
+++ parse.y 2002/01/25 05:36:02
@@ -1,6 +1,6 @@
/* Source code parsing and tree node generation for the GNU compiler
for the Java(TM) language.
- Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
This file is part of GNU CC.
@@ -7723,7 +7723,9 @@
if (METHOD_NATIVE (decl))
{
- tree body = build_jni_stub (decl);
+ tree body;
+ current_function_decl = decl;
+ body = build_jni_stub (decl);
BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (decl)) = body;
}
More information about the Java-patches
mailing list