diff options
author | bothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-08-12 06:53:42 +0000 |
---|---|---|
committer | bothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-08-12 06:53:42 +0000 |
commit | 307719b97143646f73530f046493efc507351385 (patch) | |
tree | ddcf219c5b73f37a94e4a0d174408bc041874a8e /libjava/gcj | |
parent | 3b50f8cbc13e04294332211ea899d8cf19a3e1be (diff) | |
download | gcc-307719b97143646f73530f046493efc507351385.tar.gz |
* gcj/javaprims.h (_Jv_Utf8Const): Change struct to a class,
with private fields and access methods.
(_Jv_NewStringUTF, _Jv_hashUtf8String): New function declarations.
* gcj/cni.h (_Jv_NewStringUTF): Move to javaprims.h.
* prims.cc (_Jv_Utf8COnst::init): New method implementation.
( _Jv_makeUtf8Const): Rewrite using new constructors.
(hashUtf8String): Rename to +_Jv_hashUtf8String and make non-static.
* defineclass.cc: Use new _Utf8Const access/convenience methods.
* jni.cc: Likewise.
* resolve.cc: Likewise.
* gcj/field.h: Likewise.
* include/jvm.h: Likewise.
* java/lang/Class.h: Likewise.
* java/lang/natClass.cc: Likwise.
* java/lang/natClassLoader.cc: Likewise
* java/lang/reflect/natMethod.cc: Likewise
* verify.cc: Likewise.
(_Jv_BytecodeVerifier::make_utf8_const): Optimize.
(~_Jv_BytecodeVerifier): Don't need second _Jv_Free call.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@85854 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/gcj')
-rw-r--r-- | libjava/gcj/cni.h | 1 | ||||
-rw-r--r-- | libjava/gcj/field.h | 2 | ||||
-rw-r--r-- | libjava/gcj/javaprims.h | 34 |
3 files changed, 34 insertions, 3 deletions
diff --git a/libjava/gcj/cni.h b/libjava/gcj/cni.h index b9ee3829ce1..ee39738d228 100644 --- a/libjava/gcj/cni.h +++ b/libjava/gcj/cni.h @@ -20,7 +20,6 @@ details. */ #include <string.h> -extern "C" jstring _Jv_NewStringUTF (const char *bytes); extern "C" void _Jv_InitClass (jclass); extern "C" void *_Jv_AllocBytes (jsize size) __attribute__((__malloc__)); diff --git a/libjava/gcj/field.h b/libjava/gcj/field.h index 70c5901417b..bd6b2c38046 100644 --- a/libjava/gcj/field.h +++ b/libjava/gcj/field.h @@ -68,7 +68,7 @@ struct _Jv_Field { if (!isResolved ()) { - char first = ((_Jv_Utf8Const*)type)->data[0]; + char first = ((_Jv_Utf8Const*)type)->first(); return first == '[' || first == 'L'; } else diff --git a/libjava/gcj/javaprims.h b/libjava/gcj/javaprims.h index 9cf2741cd18..09e0c5534c7 100644 --- a/libjava/gcj/javaprims.h +++ b/libjava/gcj/javaprims.h @@ -472,10 +472,13 @@ extern jint _Jv_FormatInt (jchar* bufend, jint num); extern "C" jchar* _Jv_GetStringChars (jstring str); extern "C" void _Jv_MonitorEnter (jobject); extern "C" void _Jv_MonitorExit (jobject); +extern "C" jstring _Jv_NewStringUTF (const char *bytes) + __attribute__((__malloc__)); extern "C" jstring _Jv_NewStringLatin1(const char*, jsize) __attribute__((__malloc__)); extern "C" jsize _Jv_GetStringUTFLength (jstring); extern "C" jsize _Jv_GetStringUTFRegion (jstring, jsize, jsize, char *); +extern "C" jint _Jv_hashUtf8String (char*, int); extern jint _Jv_CreateJavaVM (void* /*vm_args*/); @@ -500,11 +503,40 @@ typedef unsigned short _Jv_ushort __attribute__((__mode__(__HI__))); typedef unsigned int _Jv_uint __attribute__((__mode__(__SI__))); typedef unsigned int _Jv_ulong __attribute__((__mode__(__DI__))); -struct _Jv_Utf8Const +class _Jv_Utf8Const { _Jv_ushort hash; _Jv_ushort length; /* In bytes, of data portion, without final '\0'. */ char data[1]; /* In Utf8 format, with final '\0'. */ + public: + /** Return same value of java.lang.String's hashCode. */ + jint hash32() { return _Jv_hashUtf8String(data, length); } + /** Return a hash code that has at least 16 bits of information. */ + _Jv_ushort hash16 () { return hash; } + /** Return a hash code that has at least 8 bits of information. */ + _Jv_ushort hash8 () { return hash; } + /** Length in bytes of the UTF8-encoding. */ + _Jv_ushort len () const { return length; } + /** Pointer to the first byte in the NUL-terminated UTF8-encoding. */ + char* chars() { return data; } + /** Pointer to the NUL byte that terminated the UTF8-encoding. */ + char* limit() { return data+length; } + /** Return the first byte in the UTF8-encoding. */ + char first() const { return data[0]; } + /** Create a (non-interned) java.lang.String from this UTF8Const. */ + jstring toString() { return _Jv_NewStringUTF(data); } + /** Given an UTF8 string, how many bytes needed for a UTF8Const, + including struct header, and final NUL. I.e. what to pas to malloc. */ + static int space_needed (char *, int len) + { return sizeof (_Jv_Utf8Const) + len + 1; } + /** Given an allocated _Jv_Utf8Const, copy / fill it in. */ + void init (char *s, int len); + friend jboolean _Jv_equalUtf8Consts (const _Jv_Utf8Const*, const _Jv_Utf8Const *); + friend jboolean _Jv_equal (_Jv_Utf8Const*, jstring, jint); + friend jboolean _Jv_equaln (_Jv_Utf8Const*, jstring, jint); + friend _Jv_Utf8Const *_Jv_makeUtf8Const (char*, int); + friend _Jv_Utf8Const *_Jv_makeUtf8Const (jstring); + friend jstring _Jv_NewStringUtf8Const (_Jv_Utf8Const*); }; |