27 #include "classfile/classLoaderData.inline.hpp"
28 #include "classfile/javaClasses.inline.hpp"
29 #include "classfile/moduleEntry.hpp"
30 #include "classfile/stringTable.hpp"
31 #include "classfile/vmSymbols.hpp"
32 #include "code/debugInfo.hpp"
33 #include "code/dependencyContext.hpp"
34 #include "code/pcDesc.hpp"
35 #include "interpreter/interpreter.hpp"
36 #include "memory/oopFactory.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "memory/universe.inline.hpp"
39 #include "oops/fieldStreams.hpp"
40 #include "oops/instanceKlass.hpp"
41 #include "oops/instanceMirrorKlass.hpp"
42 #include "oops/klass.hpp"
43 #include "oops/method.hpp"
44 #include "oops/objArrayOop.inline.hpp"
45 #include "oops/oop.inline.hpp"
46 #include "oops/symbol.hpp"
47 #include "oops/typeArrayOop.hpp"
48 #include "runtime/fieldDescriptor.hpp"
49 #include "runtime/handles.inline.hpp"
50 #include "runtime/interfaceSupport.hpp"
51 #include "runtime/java.hpp"
52 #include "runtime/javaCalls.hpp"
53 #include "runtime/safepoint.hpp"
54 #include "runtime/thread.inline.hpp"
55 #include "runtime/vframe.hpp"
56 #include "utilities/preserveException.hpp"
57
58 #if INCLUDE_JVMCI
59 #include "jvmci/jvmciJavaClasses.hpp"
60 #endif
61
62 #define INJECTED_FIELD_COMPUTE_OFFSET(klass, name, signature, may_be_java) \
63 klass::_##name##_offset = JavaClasses::compute_injected_offset(JavaClasses::klass##_##name##_enum);
64
65 #define DECLARE_INJECTED_FIELD(klass, name, signature, may_be_java) \
66 { SystemDictionary::WK_KLASS_ENUM_NAME(klass), vmSymbols::VM_SYMBOL_ENUM_NAME(name##_name), vmSymbols::VM_SYMBOL_ENUM_NAME(signature), may_be_java },
67
597 } else {
598 jbyte* position = value->byte_at_addr(start);
599 return UNICODE::as_utf8(position, len);
600 }
601 }
602
603 char* java_lang_String::as_utf8_string(oop java_string, int start, int len, char* buf, int buflen) {
604 typeArrayOop value = java_lang_String::value(java_string);
605 int length = java_lang_String::length(java_string);
606 assert(start + len <= length, "just checking");
607 bool is_latin1 = java_lang_String::is_latin1(java_string);
608 if (!is_latin1) {
609 jchar* position = value->char_at_addr(start);
610 return UNICODE::as_utf8(position, len, buf, buflen);
611 } else {
612 jbyte* position = value->byte_at_addr(start);
613 return UNICODE::as_utf8(position, len, buf, buflen);
614 }
615 }
616
617 bool java_lang_String::equals(oop java_string, jchar* chars, int len) {
618 assert(java_string->klass() == SystemDictionary::String_klass(),
619 "must be java_string");
620 typeArrayOop value = java_lang_String::value(java_string);
621 int length = java_lang_String::length(java_string);
622 if (length != len) {
623 return false;
624 }
625 bool is_latin1 = java_lang_String::is_latin1(java_string);
626 if (!is_latin1) {
627 for (int i = 0; i < len; i++) {
628 if (value->char_at(i) != chars[i]) {
629 return false;
630 }
631 }
632 } else {
633 for (int i = 0; i < len; i++) {
634 if ((((jchar) value->byte_at(i)) & 0xff) != chars[i]) {
635 return false;
636 }
637 }
638 }
639 return true;
640 }
641
642 bool java_lang_String::equals(oop str1, oop str2) {
643 assert(str1->klass() == SystemDictionary::String_klass(),
644 "must be java String");
645 assert(str2->klass() == SystemDictionary::String_klass(),
646 "must be java String");
647 typeArrayOop value1 = java_lang_String::value(str1);
648 int length1 = java_lang_String::length(str1);
649 bool is_latin1 = java_lang_String::is_latin1(str1);
650 typeArrayOop value2 = java_lang_String::value(str2);
651 int length2 = java_lang_String::length(str2);
652 bool is_latin2 = java_lang_String::is_latin1(str2);
653
654 if ((length1 != length2) || (is_latin1 != is_latin2)) {
655 // Strings of different size or with different
656 // coders are never equal.
657 return false;
658 }
659 int blength1 = value1->length();
660 for (int i = 0; i < value1->length(); i++) {
661 if (value1->byte_at(i) != value2->byte_at(i)) {
662 return false;
663 }
664 }
665 return true;
666 }
667
668 void java_lang_String::print(oop java_string, outputStream* st) {
669 assert(java_string->klass() == SystemDictionary::String_klass(), "must be java_string");
670 typeArrayOop value = java_lang_String::value(java_string);
671
672 if (value == NULL) {
673 // This can happen if, e.g., printing a String
674 // object before its initializer has been called
675 st->print("NULL");
676 return;
677 }
678
679 int length = java_lang_String::length(java_string);
680 bool is_latin1 = java_lang_String::is_latin1(java_string);
|
27 #include "classfile/classLoaderData.inline.hpp"
28 #include "classfile/javaClasses.inline.hpp"
29 #include "classfile/moduleEntry.hpp"
30 #include "classfile/stringTable.hpp"
31 #include "classfile/vmSymbols.hpp"
32 #include "code/debugInfo.hpp"
33 #include "code/dependencyContext.hpp"
34 #include "code/pcDesc.hpp"
35 #include "interpreter/interpreter.hpp"
36 #include "memory/oopFactory.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "memory/universe.inline.hpp"
39 #include "oops/fieldStreams.hpp"
40 #include "oops/instanceKlass.hpp"
41 #include "oops/instanceMirrorKlass.hpp"
42 #include "oops/klass.hpp"
43 #include "oops/method.hpp"
44 #include "oops/objArrayOop.inline.hpp"
45 #include "oops/oop.inline.hpp"
46 #include "oops/symbol.hpp"
47 #include "oops/typeArrayOop.inline.hpp"
48 #include "runtime/access.inline.hpp"
49 #include "runtime/fieldDescriptor.hpp"
50 #include "runtime/handles.inline.hpp"
51 #include "runtime/interfaceSupport.hpp"
52 #include "runtime/java.hpp"
53 #include "runtime/javaCalls.hpp"
54 #include "runtime/safepoint.hpp"
55 #include "runtime/thread.inline.hpp"
56 #include "runtime/vframe.hpp"
57 #include "utilities/preserveException.hpp"
58
59 #if INCLUDE_JVMCI
60 #include "jvmci/jvmciJavaClasses.hpp"
61 #endif
62
63 #define INJECTED_FIELD_COMPUTE_OFFSET(klass, name, signature, may_be_java) \
64 klass::_##name##_offset = JavaClasses::compute_injected_offset(JavaClasses::klass##_##name##_enum);
65
66 #define DECLARE_INJECTED_FIELD(klass, name, signature, may_be_java) \
67 { SystemDictionary::WK_KLASS_ENUM_NAME(klass), vmSymbols::VM_SYMBOL_ENUM_NAME(name##_name), vmSymbols::VM_SYMBOL_ENUM_NAME(signature), may_be_java },
68
598 } else {
599 jbyte* position = value->byte_at_addr(start);
600 return UNICODE::as_utf8(position, len);
601 }
602 }
603
604 char* java_lang_String::as_utf8_string(oop java_string, int start, int len, char* buf, int buflen) {
605 typeArrayOop value = java_lang_String::value(java_string);
606 int length = java_lang_String::length(java_string);
607 assert(start + len <= length, "just checking");
608 bool is_latin1 = java_lang_String::is_latin1(java_string);
609 if (!is_latin1) {
610 jchar* position = value->char_at_addr(start);
611 return UNICODE::as_utf8(position, len, buf, buflen);
612 } else {
613 jbyte* position = value->byte_at_addr(start);
614 return UNICODE::as_utf8(position, len, buf, buflen);
615 }
616 }
617
618 bool java_lang_String::equals(typeArrayOop value, int length, oop java_string, jchar* chars, int len) {
619 assert(java_string->klass() == SystemDictionary::String_klass(),
620 "must be java_string");
621 if (length != len) {
622 return false;
623 }
624 bool is_latin1 = java_lang_String::is_latin1(java_string);
625 if (!is_latin1) {
626 for (int i = 0; i < len; i++) {
627 if (value->char_at(i) != chars[i]) {
628 return false;
629 }
630 }
631 } else {
632 for (int i = 0; i < len; i++) {
633 if ((((jchar) value->byte_at(i)) & 0xff) != chars[i]) {
634 return false;
635 }
636 }
637 }
638 return true;
639 }
640
641 bool java_lang_String::equals(oop java_string, jchar* chars, int len) {
642 typeArrayOop value = java_lang_String::value(java_string);
643 int length = java_lang_String::length(java_string);
644 return java_lang_String::equals(value, length, java_string, chars, len);
645 }
646
647 bool java_lang_String::equals(oop str1, oop str2) {
648 assert(str1->klass() == SystemDictionary::String_klass(),
649 "must be java String");
650 assert(str2->klass() == SystemDictionary::String_klass(),
651 "must be java String");
652 typeArrayOop value1 = java_lang_String::value(str1);
653 int length1 = value1->length();
654 bool is_latin1 = java_lang_String::is_latin1(str1);
655 typeArrayOop value2 = java_lang_String::value(str2);
656 int length2 = value2->length();
657 bool is_latin2 = java_lang_String::is_latin1(str2);
658
659 if ((length1 != length2) || (is_latin1 != is_latin2)) {
660 // Strings of different size or with different
661 // coders are never equal.
662 return false;
663 }
664 for (int i = 0; i < length1; i++) {
665 if (value1->byte_at(i) != value2->byte_at(i)) {
666 return false;
667 }
668 }
669 return true;
670 }
671
672 void java_lang_String::print(oop java_string, outputStream* st) {
673 assert(java_string->klass() == SystemDictionary::String_klass(), "must be java_string");
674 typeArrayOop value = java_lang_String::value(java_string);
675
676 if (value == NULL) {
677 // This can happen if, e.g., printing a String
678 // object before its initializer has been called
679 st->print("NULL");
680 return;
681 }
682
683 int length = java_lang_String::length(java_string);
684 bool is_latin1 = java_lang_String::is_latin1(java_string);
|