50 |
50 |
51 // Interface to java.lang.String objects |
51 // Interface to java.lang.String objects |
52 |
52 |
53 class java_lang_String : AllStatic { |
53 class java_lang_String : AllStatic { |
54 private: |
54 private: |
55 enum { |
|
56 hc_value_offset = 0, |
|
57 hc_offset_offset = 1 |
|
58 //hc_count_offset = 2 -- not a word-scaled offset |
|
59 //hc_hash_offset = 3 -- not a word-scaled offset |
|
60 }; |
|
61 |
|
62 static int value_offset; |
55 static int value_offset; |
63 static int offset_offset; |
56 static int offset_offset; |
64 static int count_offset; |
57 static int count_offset; |
65 static int hash_offset; |
58 static int hash_offset; |
66 |
59 |
|
60 static bool initialized; |
|
61 |
67 static Handle basic_create(int length, bool tenured, TRAPS); |
62 static Handle basic_create(int length, bool tenured, TRAPS); |
68 static Handle basic_create_from_unicode(jchar* unicode, int length, bool tenured, TRAPS); |
63 static Handle basic_create_from_unicode(jchar* unicode, int length, bool tenured, TRAPS); |
69 |
64 |
70 static void set_value( oop string, typeArrayOop buffer) { string->obj_field_put(value_offset, (oop)buffer); } |
65 static void set_value( oop string, typeArrayOop buffer) { |
71 static void set_offset(oop string, int offset) { string->int_field_put(offset_offset, offset); } |
66 assert(initialized, "Must be initialized"); |
72 static void set_count( oop string, int count) { string->int_field_put(count_offset, count); } |
67 string->obj_field_put(value_offset, (oop)buffer); |
73 |
68 } |
74 public: |
69 static void set_offset(oop string, int offset) { |
|
70 assert(initialized, "Must be initialized"); |
|
71 if (offset_offset > 0) { |
|
72 string->int_field_put(offset_offset, offset); |
|
73 } |
|
74 } |
|
75 static void set_count( oop string, int count) { |
|
76 assert(initialized, "Must be initialized"); |
|
77 if (count_offset > 0) { |
|
78 string->int_field_put(count_offset, count); |
|
79 } |
|
80 } |
|
81 |
|
82 public: |
|
83 static void compute_offsets(); |
|
84 |
75 // Instance creation |
85 // Instance creation |
76 static Handle create_from_unicode(jchar* unicode, int len, TRAPS); |
86 static Handle create_from_unicode(jchar* unicode, int len, TRAPS); |
77 static Handle create_tenured_from_unicode(jchar* unicode, int len, TRAPS); |
87 static Handle create_tenured_from_unicode(jchar* unicode, int len, TRAPS); |
78 static oop create_oop_from_unicode(jchar* unicode, int len, TRAPS); |
88 static oop create_oop_from_unicode(jchar* unicode, int len, TRAPS); |
79 static Handle create_from_str(const char* utf8_str, TRAPS); |
89 static Handle create_from_str(const char* utf8_str, TRAPS); |
80 static oop create_oop_from_str(const char* utf8_str, TRAPS); |
90 static oop create_oop_from_str(const char* utf8_str, TRAPS); |
81 static Handle create_from_symbol(Symbol* symbol, TRAPS); |
91 static Handle create_from_symbol(Symbol* symbol, TRAPS); |
82 static Handle create_from_platform_dependent_str(const char* str, TRAPS); |
92 static Handle create_from_platform_dependent_str(const char* str, TRAPS); |
83 static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS); |
93 static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS); |
84 |
94 |
85 static int value_offset_in_bytes() { return value_offset; } |
95 static bool has_offset_field() { |
86 static int count_offset_in_bytes() { return count_offset; } |
96 assert(initialized, "Must be initialized"); |
87 static int offset_offset_in_bytes() { return offset_offset; } |
97 return (offset_offset > 0); |
88 static int hash_offset_in_bytes() { return hash_offset; } |
98 } |
|
99 |
|
100 static bool has_count_field() { |
|
101 assert(initialized, "Must be initialized"); |
|
102 return (count_offset > 0); |
|
103 } |
|
104 |
|
105 static bool has_hash_field() { |
|
106 assert(initialized, "Must be initialized"); |
|
107 return (hash_offset > 0); |
|
108 } |
|
109 |
|
110 static int value_offset_in_bytes() { |
|
111 assert(initialized && (value_offset > 0), "Must be initialized"); |
|
112 return value_offset; |
|
113 } |
|
114 static int count_offset_in_bytes() { |
|
115 assert(initialized && (count_offset > 0), "Must be initialized"); |
|
116 return count_offset; |
|
117 } |
|
118 static int offset_offset_in_bytes() { |
|
119 assert(initialized && (offset_offset > 0), "Must be initialized"); |
|
120 return offset_offset; |
|
121 } |
|
122 static int hash_offset_in_bytes() { |
|
123 assert(initialized && (hash_offset > 0), "Must be initialized"); |
|
124 return hash_offset; |
|
125 } |
89 |
126 |
90 // Accessors |
127 // Accessors |
91 static typeArrayOop value(oop java_string) { |
128 static typeArrayOop value(oop java_string) { |
|
129 assert(initialized && (value_offset > 0), "Must be initialized"); |
92 assert(is_instance(java_string), "must be java_string"); |
130 assert(is_instance(java_string), "must be java_string"); |
93 return (typeArrayOop) java_string->obj_field(value_offset); |
131 return (typeArrayOop) java_string->obj_field(value_offset); |
94 } |
132 } |
95 static int offset(oop java_string) { |
133 static int offset(oop java_string) { |
|
134 assert(initialized, "Must be initialized"); |
96 assert(is_instance(java_string), "must be java_string"); |
135 assert(is_instance(java_string), "must be java_string"); |
97 return java_string->int_field(offset_offset); |
136 if (offset_offset > 0) { |
|
137 return java_string->int_field(offset_offset); |
|
138 } else { |
|
139 return 0; |
|
140 } |
98 } |
141 } |
99 static int length(oop java_string) { |
142 static int length(oop java_string) { |
|
143 assert(initialized, "Must be initialized"); |
100 assert(is_instance(java_string), "must be java_string"); |
144 assert(is_instance(java_string), "must be java_string"); |
101 return java_string->int_field(count_offset); |
145 if (count_offset > 0) { |
|
146 return java_string->int_field(count_offset); |
|
147 } else { |
|
148 return ((typeArrayOop)java_string->obj_field(value_offset))->length(); |
|
149 } |
102 } |
150 } |
103 static int utf8_length(oop java_string); |
151 static int utf8_length(oop java_string); |
104 |
152 |
105 // String converters |
153 // String converters |
106 static char* as_utf8_string(oop java_string); |
154 static char* as_utf8_string(oop java_string); |