This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Hi Bryce,
>> Here is the patch, rewritten to use the existing CNI functions.
>> To recap this supersedes and nullifies the cni.h + gcj.texi
>> patches as well as all other jvm.h patches.
>
>I'd still like to see it use JvAllocBytes instead of _Jv_Malloc. That
>way you can get rid of the destructor and the "heapAllocated" field.
>Even if it were slower, which it isn't, it will only be used in the
>rare cases where the string is > 256 bytes.
I modified the testcase (attached) to do create a gazillion instances.
You invoke the test program with -stresstest, pipe stdout to some file
and read stderr on the console.
Here are my invocations on Linux (P450/256M/10G):
./TempUTFStrTest -stresstest > stress.out
and Windows XP (P733/1G/80G):
TempUTFStrTest.exe -stresstest > d:\temp\stress.out
I ran these tests four times on each platform with the unmodified jvm.h
in the patch I just submitted (http://gcc.gnu.org/ml/java-patches/2003-q3/msg00390.html)
as well as with a jvm.h modified as per the end of this email message.
Here are the reported timings:
Linux w/_Jv_AllocBytes():
22489
20609
22161
22397
Win32 w/_Jv_AllocBytes():
84692
85403
86444
86685
(Yes, I know my WinXP box is misconfigured. Maybe I need to enable 32 bit access for my HD...)
Linux w/_Jv_Malloc():
20250
14155
17221
21747
Win32 w/_Jv_Malloc():
72604
73205
73315
72385
Let me know if I'm doing something wrong or if your results differ.
-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/
--> jvm.h Modified for _Jv_AllocBytes()
---------------------------------------------------8<------------------------------------------------------------
Index: include/jvm.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/include/jvm.h,v
retrieving revision 1.56
diff -u -2 -r1.56 jvm.h
--- include/jvm.h 21 Jul 2003 01:54:05 -0000 1.56
+++ include/jvm.h 15 Aug 2003 04:25:48 -0000
@@ -245,4 +245,80 @@
bool is_jar);
+/* Helper class which converts a jstring to a temporary char*.
+ Uses the supplied buffer, if non-null. Otherwise, allocates
+ the buffer on the heap. Use the JV_TEMP_UTF_STRING macro,
+ which follows, to automatically allocate a stack buffer if
+ the string is small enough. */
+class _Jv_TempUTFString
+{
+public:
+ _Jv_TempUTFString(jstring jstr, char* buf=0);
+ ~_Jv_TempUTFString();
+
+// Accessors
+ operator const char*() const
+ {
+ return buf_;
+ }
+ const char* buf() const
+ {
+ return buf_;
+ }
+ char* buf()
+ {
+ return buf_;
+ }
+
+private:
+ char* buf_;
+ bool heapAllocated_;
+};
+
+inline _Jv_TempUTFString::_Jv_TempUTFString (jstring jstr, char* buf)
+ : buf_(0), heapAllocated_(false)
+{
+ if (!jstr) return;
+ jsize len = JvGetStringUTFLength (jstr);
+ if (buf)
+ buf_ = buf;
+ else
+ {
+// buf_ = (char*) _Jv_Malloc (len+1);
+ buf_ = (char*) _Jv_AllocBytes (len+1);
+// heapAllocated_ = true;
+ }
+
+ JvGetStringUTFRegion (jstr, 0, jstr->length(), buf_);
+ buf_[len] = '\0';
+}
+
+inline _Jv_TempUTFString::~_Jv_TempUTFString ()
+{
+/*
+ if (heapAllocated_)
+ _Jv_Free (buf_);
+*/
+}
+
+/* Macro which uses _Jv_TempUTFString. Allocates a stack-based
+ buffer if the string and its null terminator are <= 256
+ characters in length. Otherwise, a heap-based buffer is
+ used. The parameters to this macro are the variable name
+ which is an instance of _Jv_TempUTFString (above) and a
+ jstring.
+
+ Sample Usage:
+
+ jstring jstr = getAJString();
+ JV_TEMP_UTF_STRING(utfstr, jstr);
+ printf("The string is: %s\n", utfstr.buf());
+
+ */
+#define JV_TEMP_UTF_STRING(utfstr, jstr) \
+ jstring utfstr##thejstr = (jstr); \
+ jsize utfstr##_len = utfstr##thejstr ? JvGetStringUTFLength (utfstr##thejstr) + 1 : 0; \
+ char utfstr##_buf[utfstr##_len <= 256 ? utfstr##_len : 0]; \
+ _Jv_TempUTFString utfstr(utfstr##thejstr, sizeof(utfstr##_buf)==0 ? 0 : utfstr##_buf)
+
// Delayed until after _Jv_AllocBytes is declared.
//
---------------------------------------------------8<------------------------------------------------------------
Attachment:
TempUTFStrTest.tar.bz2
Description: application/bzip2
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |