This is the mail archive of the
java-patches@sources.redhat.com
mailing list for the Java project.
Patch: fix for stringconst2 test
- To: Java Patch List <java-patches at sourceware dot cygnus dot com>
- Subject: Patch: fix for stringconst2 test
- From: Tom Tromey <tromey at cygnus dot com>
- Date: 07 Jul 2000 15:00:53 -0600
- Reply-To: tromey at cygnus dot com
I'm checking this in.
We failed to initialize `static final String' fields in the runtime.
(gcj -C never generates these in the .class files, which is itself a
bug...)
As a result sometimes gcj-compiled class files would crash as they
tried to use a utf8const as if it were a String.
This patch fixes the problem, though perhaps not in the prettiest way.
2000-07-06 Tom Tromey <tromey@cygnus.com>
* java/lang/natClassLoader.cc (_Jv_PrepareCompiledClass):
Initialize static final String fields.
Tom
Index: java/lang/natClassLoader.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natClassLoader.cc,v
retrieving revision 1.23
diff -u -r1.23 natClassLoader.cc
--- natClassLoader.cc 2000/05/31 23:50:37 1.23
+++ natClassLoader.cc 2000/07/07 20:53:18
@@ -261,7 +261,6 @@
pool->data[index].clazz = found;
pool->tags[index] |= JV_CONSTANT_ResolvedFlag;
}
-
else if (pool->tags[index] == JV_CONSTANT_String)
{
jstring str;
@@ -269,6 +268,24 @@
pool->data[index].o = str;
pool->tags[index] |= JV_CONSTANT_ResolvedFlag;
}
+ }
+
+ jfieldID f = JvGetFirstStaticField (klass);
+ for (int n = JvNumStaticFields (klass); n > 0; --n)
+ {
+ int mod = f->getModifiers ();
+ // Maybe the compiler should mark these with
+ // _Jv_FIELD_CONSTANT_VALUE? For now we just know that this
+ // only happens for constant strings.
+ if (f->getClass () == &StringClass
+ && java::lang::reflect::Modifier::isStatic (mod)
+ && java::lang::reflect::Modifier::isFinal (mod))
+ {
+ jstring *strp = (jstring *) f->u.addr;
+ if (*strp)
+ *strp = _Jv_NewStringUtf8Const ((_Jv_Utf8Const *) *strp);
+ }
+ f = f->getNextField ();
}
klass->notifyAll ();