292
293 oop java_lang_String::create_oop_from_unicode(jchar* unicode, int length, TRAPS) {
294 Handle h_obj = create_from_unicode(unicode, length, CHECK_0);
295 return h_obj();
296 }
297
298 Handle java_lang_String::create_from_str(const char* utf8_str, TRAPS) {
299 if (utf8_str == NULL) {
300 return Handle();
301 }
302 bool has_multibyte, is_latin1;
303 int length = UTF8::unicode_length(utf8_str, is_latin1, has_multibyte);
304 if (!CompactStrings) {
305 has_multibyte = true;
306 is_latin1 = false;
307 }
308
309 Handle h_obj = basic_create(length, is_latin1, CHECK_NH);
310 if (length > 0) {
311 if (!has_multibyte) {
312 ArrayAccess<>::arraycopy_from_native<>(reinterpret_cast<const jbyte*>(utf8_str), value(h_obj()), typeArrayOopDesc::element_offs
313 } else if (is_latin1) {
314 UTF8::convert_to_unicode(utf8_str, value(h_obj())->byte_at_addr(0), length);
315 } else {
316 UTF8::convert_to_unicode(utf8_str, value(h_obj())->char_at_addr(0), length);
317 }
318 }
319
320 #ifdef ASSERT
321 // This check is too strict because the input string is not necessarily valid UTF8.
322 // For example, it may be created with arbitrary content via jni_NewStringUTF.
323 /*
324 {
325 ResourceMark rm;
326 const char* expected = utf8_str;
327 char* actual = as_utf8_string(h_obj());
328 if (strcmp(expected, actual) != 0) {
329 tty->print_cr("String conversion failure: %s --> %s", expected, actual);
330 ShouldNotReachHere();
331 }
|
292
293 oop java_lang_String::create_oop_from_unicode(jchar* unicode, int length, TRAPS) {
294 Handle h_obj = create_from_unicode(unicode, length, CHECK_0);
295 return h_obj();
296 }
297
298 Handle java_lang_String::create_from_str(const char* utf8_str, TRAPS) {
299 if (utf8_str == NULL) {
300 return Handle();
301 }
302 bool has_multibyte, is_latin1;
303 int length = UTF8::unicode_length(utf8_str, is_latin1, has_multibyte);
304 if (!CompactStrings) {
305 has_multibyte = true;
306 is_latin1 = false;
307 }
308
309 Handle h_obj = basic_create(length, is_latin1, CHECK_NH);
310 if (length > 0) {
311 if (!has_multibyte) {
312 const jbyte* src = reinterpret_cast<const jbyte*>(utf8_str);
313 ArrayAccess<>::arraycopy_from_native(src, value(h_obj()), typeArrayOopDesc::element_offset<jbyte>(0), length);
314 } else if (is_latin1) {
315 UTF8::convert_to_unicode(utf8_str, value(h_obj())->byte_at_addr(0), length);
316 } else {
317 UTF8::convert_to_unicode(utf8_str, value(h_obj())->char_at_addr(0), length);
318 }
319 }
320
321 #ifdef ASSERT
322 // This check is too strict because the input string is not necessarily valid UTF8.
323 // For example, it may be created with arbitrary content via jni_NewStringUTF.
324 /*
325 {
326 ResourceMark rm;
327 const char* expected = utf8_str;
328 char* actual = as_utf8_string(h_obj());
329 if (strcmp(expected, actual) != 0) {
330 tty->print_cr("String conversion failure: %s --> %s", expected, actual);
331 ShouldNotReachHere();
332 }
|
338
339 oop java_lang_String::create_oop_from_str(const char* utf8_str, TRAPS) {
340 Handle h_obj = create_from_str(utf8_str, CHECK_0);
341 return h_obj();
342 }
343
344 Handle java_lang_String::create_from_symbol(Symbol* symbol, TRAPS) {
345 const char* utf8_str = (char*)symbol->bytes();
346 int utf8_len = symbol->utf8_length();
347
348 bool has_multibyte, is_latin1;
349 int length = UTF8::unicode_length(utf8_str, utf8_len, is_latin1, has_multibyte);
350 if (!CompactStrings) {
351 has_multibyte = true;
352 is_latin1 = false;
353 }
354
355 Handle h_obj = basic_create(length, is_latin1, CHECK_NH);
356 if (length > 0) {
357 if (!has_multibyte) {
358 ArrayAccess<>::arraycopy_from_native<>(reinterpret_cast<const jbyte*>(utf8_str), value(h_obj()), typeArrayOopDesc::element_offs
359 } else if (is_latin1) {
360 UTF8::convert_to_unicode(utf8_str, value(h_obj())->byte_at_addr(0), length);
361 } else {
362 UTF8::convert_to_unicode(utf8_str, value(h_obj())->char_at_addr(0), length);
363 }
364 }
365
366 #ifdef ASSERT
367 {
368 ResourceMark rm;
369 const char* expected = symbol->as_utf8();
370 char* actual = as_utf8_string(h_obj());
371 if (strncmp(expected, actual, utf8_len) != 0) {
372 tty->print_cr("Symbol conversion failure: %s --> %s", expected, actual);
373 ShouldNotReachHere();
374 }
375 }
376 #endif
377
|
339
340 oop java_lang_String::create_oop_from_str(const char* utf8_str, TRAPS) {
341 Handle h_obj = create_from_str(utf8_str, CHECK_0);
342 return h_obj();
343 }
344
345 Handle java_lang_String::create_from_symbol(Symbol* symbol, TRAPS) {
346 const char* utf8_str = (char*)symbol->bytes();
347 int utf8_len = symbol->utf8_length();
348
349 bool has_multibyte, is_latin1;
350 int length = UTF8::unicode_length(utf8_str, utf8_len, is_latin1, has_multibyte);
351 if (!CompactStrings) {
352 has_multibyte = true;
353 is_latin1 = false;
354 }
355
356 Handle h_obj = basic_create(length, is_latin1, CHECK_NH);
357 if (length > 0) {
358 if (!has_multibyte) {
359 const jbyte* src = reinterpret_cast<const jbyte*>(utf8_str);
360 ArrayAccess<>::arraycopy_from_native(src, value(h_obj()), typeArrayOopDesc::element_offset<jbyte>(0), length);
361 } else if (is_latin1) {
362 UTF8::convert_to_unicode(utf8_str, value(h_obj())->byte_at_addr(0), length);
363 } else {
364 UTF8::convert_to_unicode(utf8_str, value(h_obj())->char_at_addr(0), length);
365 }
366 }
367
368 #ifdef ASSERT
369 {
370 ResourceMark rm;
371 const char* expected = symbol->as_utf8();
372 char* actual = as_utf8_string(h_obj());
373 if (strncmp(expected, actual, utf8_len) != 0) {
374 tty->print_cr("Symbol conversion failure: %s --> %s", expected, actual);
375 ShouldNotReachHere();
376 }
377 }
378 #endif
379
|