145 return java_string->int_field(offset_offset);
146 } else {
147 return 0;
148 }
149 }
150 static int length(oop java_string) {
151 assert(initialized, "Must be initialized");
152 assert(is_instance(java_string), "must be java_string");
153 if (count_offset > 0) {
154 return java_string->int_field(count_offset);
155 } else {
156 return ((typeArrayOop)java_string->obj_field(value_offset))->length();
157 }
158 }
159 static int utf8_length(oop java_string);
160
161 // String converters
162 static char* as_utf8_string(oop java_string);
163 static char* as_utf8_string(oop java_string, char* buf, int buflen);
164 static char* as_utf8_string(oop java_string, int start, int len);
165 static char* as_platform_dependent_str(Handle java_string, TRAPS);
166 static jchar* as_unicode_string(oop java_string, int& length, TRAPS);
167 // produce an ascii string with all other values quoted using \u####
168 static char* as_quoted_ascii(oop java_string);
169
170 // Compute the hash value for a java.lang.String object which would
171 // contain the characters passed in.
172 //
173 // As the hash value used by the String object itself, in
174 // String.hashCode(). This value is normally calculated in Java code
175 // in the String.hashCode method(), but is precomputed for String
176 // objects in the shared archive file.
177 // hash P(31) from Kernighan & Ritchie
178 //
179 // For this reason, THIS ALGORITHM MUST MATCH String.hashCode().
180 template <typename T> static unsigned int hash_code(T* s, int len) {
181 unsigned int h = 0;
182 while (len-- > 0) {
183 h = 31*h + (unsigned int) *s;
184 s++;
|
145 return java_string->int_field(offset_offset);
146 } else {
147 return 0;
148 }
149 }
150 static int length(oop java_string) {
151 assert(initialized, "Must be initialized");
152 assert(is_instance(java_string), "must be java_string");
153 if (count_offset > 0) {
154 return java_string->int_field(count_offset);
155 } else {
156 return ((typeArrayOop)java_string->obj_field(value_offset))->length();
157 }
158 }
159 static int utf8_length(oop java_string);
160
161 // String converters
162 static char* as_utf8_string(oop java_string);
163 static char* as_utf8_string(oop java_string, char* buf, int buflen);
164 static char* as_utf8_string(oop java_string, int start, int len);
165 static char* as_utf8_string(oop java_string, int start, int len, char* buf, int buflen);
166 static char* as_platform_dependent_str(Handle java_string, TRAPS);
167 static jchar* as_unicode_string(oop java_string, int& length, TRAPS);
168 // produce an ascii string with all other values quoted using \u####
169 static char* as_quoted_ascii(oop java_string);
170
171 // Compute the hash value for a java.lang.String object which would
172 // contain the characters passed in.
173 //
174 // As the hash value used by the String object itself, in
175 // String.hashCode(). This value is normally calculated in Java code
176 // in the String.hashCode method(), but is precomputed for String
177 // objects in the shared archive file.
178 // hash P(31) from Kernighan & Ritchie
179 //
180 // For this reason, THIS ALGORITHM MUST MATCH String.hashCode().
181 template <typename T> static unsigned int hash_code(T* s, int len) {
182 unsigned int h = 0;
183 while (len-- > 0) {
184 h = 31*h + (unsigned int) *s;
185 s++;
|