Commit 83c64db6 by Tom Tromey Committed by Tom Tromey

jni.cc (_Jv_JNI_GetAnyFieldID): Handle unresolved fields.

	* jni.cc (_Jv_JNI_GetAnyFieldID): Handle unresolved fields.
	* java/lang/reflect/natField.cc (getType): Use _Jv_ResolveField
	unconditionally.
	* include/jvm.h (_Jv_ResolveField): Declare.
	* include/java-interp.h (_Jv_ResolveField): Don't declare.
	* resolve.cc (_Jv_ResolveField): No longer conditional on
	INTERPRETER.

From-SVN: r40785
parent e9f4fa71
2001-03-22 Tom Tromey <tromey@redhat.com>
* jni.cc (_Jv_JNI_GetAnyFieldID): Handle unresolved fields.
* java/lang/reflect/natField.cc (getType): Use _Jv_ResolveField
unconditionally.
* include/jvm.h (_Jv_ResolveField): Declare.
* include/java-interp.h (_Jv_ResolveField): Don't declare.
* resolve.cc (_Jv_ResolveField): No longer conditional on
INTERPRETER.
2001-03-23 Bryce McKinlay <bryce@albatross.co.nz> 2001-03-23 Bryce McKinlay <bryce@albatross.co.nz>
Fix for PR libgcj/1736. Thanks to Robert Boehne and Alexandre Oliva Fix for PR libgcj/1736. Thanks to Robert Boehne and Alexandre Oliva
......
// java-interp.h - Header file for the bytecode interpreter. -*- c++ -*- // java-interp.h - Header file for the bytecode interpreter. -*- c++ -*-
/* Copyright (C) 1999, 2000 Free Software Foundation /* Copyright (C) 1999, 2000, 2001 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -40,7 +40,6 @@ bool _Jv_VerifyClassName (_Jv_Utf8Const *name); ...@@ -40,7 +40,6 @@ bool _Jv_VerifyClassName (_Jv_Utf8Const *name);
bool _Jv_VerifyIdentifier (_Jv_Utf8Const *); bool _Jv_VerifyIdentifier (_Jv_Utf8Const *);
bool _Jv_ClassNameSamePackage (_Jv_Utf8Const *name1, _Jv_Utf8Const *name2); bool _Jv_ClassNameSamePackage (_Jv_Utf8Const *name1, _Jv_Utf8Const *name2);
void _Jv_DefineClass (jclass, jbyteArray, jint, jint); void _Jv_DefineClass (jclass, jbyteArray, jint, jint);
void _Jv_ResolveField (_Jv_Field *, java::lang::ClassLoader*);
void _Jv_InitField (jobject, jclass, int); void _Jv_InitField (jobject, jclass, int);
void * _Jv_AllocMethodInvocation (jsize size); void * _Jv_AllocMethodInvocation (jsize size);
......
// jvm.h - Header file for private implementation information. -*- c++ -*- // jvm.h - Header file for private implementation information. -*- c++ -*-
/* Copyright (C) 1998, 1999, 2000 Free Software Foundation /* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -219,6 +219,7 @@ extern "C" void _Jv_CheckArrayStore (jobject array, jobject obj); ...@@ -219,6 +219,7 @@ extern "C" void _Jv_CheckArrayStore (jobject array, jobject obj);
extern "C" void _Jv_RegisterClass (jclass klass); extern "C" void _Jv_RegisterClass (jclass klass);
extern "C" void _Jv_RegisterClasses (jclass *classes); extern "C" void _Jv_RegisterClasses (jclass *classes);
extern void _Jv_UnregisterClass (_Jv_Utf8Const*, java::lang::ClassLoader*); extern void _Jv_UnregisterClass (_Jv_Utf8Const*, java::lang::ClassLoader*);
extern void _Jv_ResolveField (_Jv_Field *, java::lang::ClassLoader*);
extern jclass _Jv_FindClass (_Jv_Utf8Const *name, extern jclass _Jv_FindClass (_Jv_Utf8Const *name,
java::lang::ClassLoader *loader); java::lang::ClassLoader *loader);
......
...@@ -678,7 +678,7 @@ java::lang::Class::finalize (void) ...@@ -678,7 +678,7 @@ java::lang::Class::finalize (void)
void void
java::lang::Class::initializeClass (void) java::lang::Class::initializeClass (void)
{ {
// jshort-circuit to avoid needless locking. // short-circuit to avoid needless locking.
if (state == JV_STATE_DONE) if (state == JV_STATE_DONE)
return; return;
...@@ -713,7 +713,9 @@ java::lang::Class::initializeClass (void) ...@@ -713,7 +713,9 @@ java::lang::Class::initializeClass (void)
wait (); wait ();
// Steps 3 & 4. // Steps 3 & 4.
if (state == JV_STATE_DONE || state == JV_STATE_IN_PROGRESS || thread == self) if (state == JV_STATE_DONE
|| state == JV_STATE_IN_PROGRESS
|| thread == self)
{ {
_Jv_MonitorExit (this); _Jv_MonitorExit (this);
return; return;
......
// natField.cc - Implementation of java.lang.reflect.Field native methods. // natField.cc - Implementation of java.lang.reflect.Field native methods.
/* Copyright (C) 1998, 1999, 2000 Free Software Foundation /* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -44,17 +44,8 @@ jclass ...@@ -44,17 +44,8 @@ jclass
java::lang::reflect::Field::getType () java::lang::reflect::Field::getType ()
{ {
jfieldID fld = _Jv_FromReflectedField (this); jfieldID fld = _Jv_FromReflectedField (this);
if (! fld->isResolved()) JvSynchronize sync (declaringClass);
{ _Jv_ResolveField (fld, declaringClass->getClassLoader ());
JvSynchronize sync (declaringClass);
if (! fld->isResolved())
{
fld->type
= _Jv_FindClassFromSignature(((Utf8Const*) (fld->type))->data,
declaringClass->getClassLoader());
fld->flags &= ~_Jv_FIELD_UNRESOLVED_FLAG;
}
}
return fld->type; return fld->type;
} }
......
...@@ -1068,8 +1068,13 @@ _Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz, ...@@ -1068,8 +1068,13 @@ _Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz,
// FIXME: what if field_class == NULL? // FIXME: what if field_class == NULL?
java::lang::ClassLoader *loader = clazz->getClassLoader ();
while (clazz != NULL) while (clazz != NULL)
{ {
// We acquire the class lock so that fields aren't resolved
// while we are running.
JvSynchronize sync (clazz);
jint count = (is_static jint count = (is_static
? JvNumStaticFields (clazz) ? JvNumStaticFields (clazz)
: JvNumInstanceFields (clazz)); : JvNumInstanceFields (clazz));
...@@ -1078,12 +1083,11 @@ _Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz, ...@@ -1078,12 +1083,11 @@ _Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz,
: JvGetFirstInstanceField (clazz)); : JvGetFirstInstanceField (clazz));
for (jint i = 0; i < count; ++i) for (jint i = 0; i < count; ++i)
{ {
// The field is resolved as a side effect of class
// initialization.
JvAssert (field->isResolved ());
_Jv_Utf8Const *f_name = field->getNameUtf8Const(clazz); _Jv_Utf8Const *f_name = field->getNameUtf8Const(clazz);
// The field might be resolved or it might not be. It
// is much simpler to always resolve it.
_Jv_ResolveField (field, loader);
if (_Jv_equalUtf8Consts (f_name, a_name) if (_Jv_equalUtf8Consts (f_name, a_name)
&& field->getClass() == field_class) && field->getClass() == field_class)
return field; return field;
......
// resolve.cc - Code for linking and resolving classes and pool entries. // resolve.cc - Code for linking and resolving classes and pool entries.
/* Copyright (C) 1999, 2000 Free Software Foundation /* Copyright (C) 1999, 2000, 2001 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -32,6 +32,17 @@ details. */ ...@@ -32,6 +32,17 @@ details. */
#include <java/lang/IncompatibleClassChangeError.h> #include <java/lang/IncompatibleClassChangeError.h>
#include <java/lang/reflect/Modifier.h> #include <java/lang/reflect/Modifier.h>
void
_Jv_ResolveField (_Jv_Field *field, java::lang::ClassLoader *loader)
{
if (! field->isResolved ())
{
_Jv_Utf8Const *sig = (_Jv_Utf8Const*)field->type;
field->type = _Jv_FindClassFromSignature (sig->data, loader);
field->flags &= ~_Jv_FIELD_UNRESOLVED_FLAG;
}
}
#ifdef INTERPRETER #ifdef INTERPRETER
static void throw_internal_error (char *msg) static void throw_internal_error (char *msg)
...@@ -361,17 +372,6 @@ _Jv_SearchMethodInClass (jclass cls, jclass klass, ...@@ -361,17 +372,6 @@ _Jv_SearchMethodInClass (jclass cls, jclass klass,
return 0; return 0;
} }
void
_Jv_ResolveField (_Jv_Field *field, java::lang::ClassLoader *loader)
{
if (! field->isResolved ())
{
_Jv_Utf8Const *sig = (_Jv_Utf8Const*)field->type;
field->type = _Jv_FindClassFromSignature (sig->data, loader);
field->flags &= ~_Jv_FIELD_UNRESOLVED_FLAG;
}
}
/** FIXME: this is a terribly inefficient algorithm! It would improve /** FIXME: this is a terribly inefficient algorithm! It would improve
things if compiled classes to know vtable offset, and _Jv_Method had things if compiled classes to know vtable offset, and _Jv_Method had
a field for this. a field for this.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment