1 /*
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
43 // Note that fields (static and non-static) are arranged with oops before non-oops
44 // on a per class basis. The offsets below have to reflect this ordering.
45 //
46 // When editing the layouts please update the check_offset verification code
47 // correspondingly. The names in the enums must be identical to the actual field
48 // names in order for the verification code to work.
49
50
51 // Interface to java.lang.String objects
52
53 class java_lang_String : AllStatic {
54 private:
55 static int value_offset;
56 static int hash_offset;
57 static int coder_offset;
58
59 static bool initialized;
60
61 static Handle basic_create(int length, bool byte_arr, TRAPS);
62
63 static void set_coder(oop string, jbyte coder) {
64 assert(initialized, "Must be initialized");
65 if (coder_offset > 0) {
66 string->byte_field_put(coder_offset, coder);
67 }
68 }
69
70 public:
71
72 // Coders
73 enum Coder {
74 CODER_LATIN1 = 0,
75 CODER_UTF16 = 1
76 };
77
78 static void compute_offsets();
79
80 // Instance creation
81 static Handle create_from_unicode(jchar* unicode, int len, TRAPS);
82 static oop create_oop_from_unicode(jchar* unicode, int len, TRAPS);
83 static Handle create_from_str(const char* utf8_str, TRAPS);
84 static oop create_oop_from_str(const char* utf8_str, TRAPS);
85 static Handle create_from_symbol(Symbol* symbol, TRAPS);
86 static Handle create_from_platform_dependent_str(const char* str, TRAPS);
87 static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS);
88
93 static bool has_coder_field() {
94 assert(initialized, "Must be initialized");
95 return (coder_offset > 0);
96 }
97
98 static void set_compact_strings(bool value);
99
100 static int value_offset_in_bytes() {
101 assert(initialized && (value_offset > 0), "Must be initialized");
102 return value_offset;
103 }
104 static int hash_offset_in_bytes() {
105 assert(initialized && (hash_offset > 0), "Must be initialized");
106 return hash_offset;
107 }
108 static int coder_offset_in_bytes() {
109 assert(initialized && (coder_offset > 0), "Must be initialized");
110 return coder_offset;
111 }
112
113 static void set_value_raw(oop string, typeArrayOop buffer) {
114 assert(initialized, "Must be initialized");
115 string->obj_field_put_raw(value_offset, buffer);
116 }
117 static void set_value(oop string, typeArrayOop buffer) {
118 assert(initialized && (value_offset > 0), "Must be initialized");
119 string->obj_field_put(value_offset, (oop)buffer);
120 }
121 static void set_hash(oop string, unsigned int hash) {
122 assert(initialized && (hash_offset > 0), "Must be initialized");
123 string->int_field_put(hash_offset, hash);
124 }
125
126 // Accessors
127 static typeArrayOop value(oop java_string) {
128 assert(initialized && (value_offset > 0), "Must be initialized");
129 assert(is_instance(java_string), "must be java_string");
130 return (typeArrayOop) java_string->obj_field(value_offset);
131 }
132 static unsigned int hash(oop java_string) {
133 assert(initialized && (hash_offset > 0), "Must be initialized");
134 assert(is_instance(java_string), "must be java_string");
135 return java_string->int_field(hash_offset);
136 }
137 static bool is_latin1(oop java_string) {
138 assert(initialized, "Must be initialized");
139 assert(is_instance(java_string), "must be java_string");
140 if (coder_offset > 0) {
141 jbyte coder = java_string->byte_field(coder_offset);
142 assert(CompactStrings || coder == CODER_UTF16, "Must be UTF16 without CompactStrings");
143 return coder == CODER_LATIN1;
144 } else {
145 return false;
146 }
147 }
148 static int length(oop java_string) {
149 assert(initialized, "Must be initialized");
150 assert(is_instance(java_string), "must be java_string");
151 typeArrayOop value_array = ((typeArrayOop)java_string->obj_field(value_offset));
152 if (value_array == NULL) {
153 return 0;
154 }
155 int arr_length = value_array->length();
156 if (!is_latin1(java_string)) {
157 assert((arr_length & 1) == 0, "should be even for UTF16 string");
158 arr_length >>= 1; // convert number of bytes to number of elements
159 }
160 return arr_length;
161 }
162 static int utf8_length(oop java_string);
163
164 // String converters
165 static char* as_utf8_string(oop java_string);
166 static char* as_utf8_string(oop java_string, char* buf, int buflen);
167 static char* as_utf8_string(oop java_string, int start, int len);
168 static char* as_utf8_string(oop java_string, int start, int len, char* buf, int buflen);
169 static char* as_platform_dependent_str(Handle java_string, TRAPS);
170 static jchar* as_unicode_string(oop java_string, int& length, TRAPS);
171 // produce an ascii string with all other values quoted using \u####
172 static char* as_quoted_ascii(oop java_string);
173
174 // Compute the hash value for a java.lang.String object which would
175 // contain the characters passed in.
176 //
177 // As the hash value used by the String object itself, in
178 // String.hashCode(). This value is normally calculated in Java code
179 // in the String.hashCode method(), but is precomputed for String
180 // objects in the shared archive file.
181 // hash P(31) from Kernighan & Ritchie
202 static unsigned int hash_code(oop java_string);
203 static unsigned int latin1_hash_code(typeArrayOop value, int len);
204
205 // This is the string hash code used by the StringTable, which may be
206 // the same as String.hashCode or an alternate hash code.
207 static unsigned int hash_string(oop java_string);
208
209 static bool equals(oop java_string, jchar* chars, int len);
210 static bool equals(oop str1, oop str2);
211
212 // Conversion between '.' and '/' formats
213 static Handle externalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '/', '.', THREAD); }
214 static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }
215
216 // Conversion
217 static Symbol* as_symbol(Handle java_string, TRAPS);
218 static Symbol* as_symbol_or_null(oop java_string);
219
220 // Testers
221 static bool is_instance(oop obj);
222 static bool is_instance_inlined(oop obj);
223
224 // Debugging
225 static void print(oop java_string, outputStream* st);
226 friend class JavaClasses;
227 friend class StringTable;
228 };
229
230
231 // Interface to java.lang.Class objects
232
233 #define CLASS_INJECTED_FIELDS(macro) \
234 macro(java_lang_Class, klass, intptr_signature, false) \
235 macro(java_lang_Class, array_klass, intptr_signature, false) \
236 macro(java_lang_Class, oop_size, int_signature, false) \
237 macro(java_lang_Class, static_oop_field_count, int_signature, false) \
238 macro(java_lang_Class, protection_domain, object_signature, false) \
239 macro(java_lang_Class, signers, object_signature, false)
240
241 class java_lang_Class : AllStatic {
242 friend class VMStructs;
893 enum {
894 hc_referent_offset = 0,
895 hc_queue_offset = 1,
896 hc_next_offset = 2,
897 hc_discovered_offset = 3 // Is not last, see SoftRefs.
898 };
899 enum {
900 hc_static_lock_offset = 0,
901 hc_static_pending_offset = 1
902 };
903
904 static int referent_offset;
905 static int queue_offset;
906 static int next_offset;
907 static int discovered_offset;
908 static int static_lock_offset;
909 static int static_pending_offset;
910 static int number_of_fake_oop_fields;
911
912 // Accessors
913 static oop referent(oop ref) {
914 return ref->obj_field(referent_offset);
915 }
916 static void set_referent(oop ref, oop value) {
917 ref->obj_field_put(referent_offset, value);
918 }
919 static void set_referent_raw(oop ref, oop value) {
920 ref->obj_field_put_raw(referent_offset, value);
921 }
922 static HeapWord* referent_addr(oop ref) {
923 return ref->obj_field_addr<HeapWord>(referent_offset);
924 }
925 static oop next(oop ref) {
926 return ref->obj_field(next_offset);
927 }
928 static void set_next(oop ref, oop value) {
929 ref->obj_field_put(next_offset, value);
930 }
931 static void set_next_raw(oop ref, oop value) {
932 ref->obj_field_put_raw(next_offset, value);
933 }
934 static HeapWord* next_addr(oop ref) {
935 return ref->obj_field_addr<HeapWord>(next_offset);
936 }
937 static oop discovered(oop ref) {
938 return ref->obj_field(discovered_offset);
939 }
940 static void set_discovered(oop ref, oop value) {
941 ref->obj_field_put(discovered_offset, value);
942 }
943 static void set_discovered_raw(oop ref, oop value) {
944 ref->obj_field_put_raw(discovered_offset, value);
945 }
946 static HeapWord* discovered_addr(oop ref) {
947 return ref->obj_field_addr<HeapWord>(discovered_offset);
948 }
949 // Accessors for statics
950 static oop pending_list_lock();
951 static oop pending_list();
952
953 static HeapWord* pending_list_lock_addr();
954 static HeapWord* pending_list_addr();
955 };
956
957
958 // Interface to java.lang.ref.SoftReference objects
959
960 class java_lang_ref_SoftReference: public java_lang_ref_Reference {
961 public:
962 enum {
963 // The timestamp is a long field and may need to be adjusted for alignment.
964 hc_timestamp_offset = hc_discovered_offset + 1
965 };
966 enum {
967 hc_static_clock_offset = 0
968 };
|
1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
43 // Note that fields (static and non-static) are arranged with oops before non-oops
44 // on a per class basis. The offsets below have to reflect this ordering.
45 //
46 // When editing the layouts please update the check_offset verification code
47 // correspondingly. The names in the enums must be identical to the actual field
48 // names in order for the verification code to work.
49
50
51 // Interface to java.lang.String objects
52
53 class java_lang_String : AllStatic {
54 private:
55 static int value_offset;
56 static int hash_offset;
57 static int coder_offset;
58
59 static bool initialized;
60
61 static Handle basic_create(int length, bool byte_arr, TRAPS);
62
63 static inline void set_coder(oop string, jbyte coder);
64
65 public:
66
67 // Coders
68 enum Coder {
69 CODER_LATIN1 = 0,
70 CODER_UTF16 = 1
71 };
72
73 static void compute_offsets();
74
75 // Instance creation
76 static Handle create_from_unicode(jchar* unicode, int len, TRAPS);
77 static oop create_oop_from_unicode(jchar* unicode, int len, TRAPS);
78 static Handle create_from_str(const char* utf8_str, TRAPS);
79 static oop create_oop_from_str(const char* utf8_str, TRAPS);
80 static Handle create_from_symbol(Symbol* symbol, TRAPS);
81 static Handle create_from_platform_dependent_str(const char* str, TRAPS);
82 static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS);
83
88 static bool has_coder_field() {
89 assert(initialized, "Must be initialized");
90 return (coder_offset > 0);
91 }
92
93 static void set_compact_strings(bool value);
94
95 static int value_offset_in_bytes() {
96 assert(initialized && (value_offset > 0), "Must be initialized");
97 return value_offset;
98 }
99 static int hash_offset_in_bytes() {
100 assert(initialized && (hash_offset > 0), "Must be initialized");
101 return hash_offset;
102 }
103 static int coder_offset_in_bytes() {
104 assert(initialized && (coder_offset > 0), "Must be initialized");
105 return coder_offset;
106 }
107
108 static inline void set_value_raw(oop string, typeArrayOop buffer);
109 static inline void set_value(oop string, typeArrayOop buffer);
110 static inline void set_hash(oop string, unsigned int hash);
111
112 // Accessors
113 static inline typeArrayOop value(oop java_string);
114 static inline unsigned int hash(oop java_string);
115 static inline bool is_latin1(oop java_string);
116 static inline int length(oop java_string);
117 static int utf8_length(oop java_string);
118
119 // String converters
120 static char* as_utf8_string(oop java_string);
121 static char* as_utf8_string(oop java_string, char* buf, int buflen);
122 static char* as_utf8_string(oop java_string, int start, int len);
123 static char* as_utf8_string(oop java_string, int start, int len, char* buf, int buflen);
124 static char* as_platform_dependent_str(Handle java_string, TRAPS);
125 static jchar* as_unicode_string(oop java_string, int& length, TRAPS);
126 // produce an ascii string with all other values quoted using \u####
127 static char* as_quoted_ascii(oop java_string);
128
129 // Compute the hash value for a java.lang.String object which would
130 // contain the characters passed in.
131 //
132 // As the hash value used by the String object itself, in
133 // String.hashCode(). This value is normally calculated in Java code
134 // in the String.hashCode method(), but is precomputed for String
135 // objects in the shared archive file.
136 // hash P(31) from Kernighan & Ritchie
157 static unsigned int hash_code(oop java_string);
158 static unsigned int latin1_hash_code(typeArrayOop value, int len);
159
160 // This is the string hash code used by the StringTable, which may be
161 // the same as String.hashCode or an alternate hash code.
162 static unsigned int hash_string(oop java_string);
163
164 static bool equals(oop java_string, jchar* chars, int len);
165 static bool equals(oop str1, oop str2);
166
167 // Conversion between '.' and '/' formats
168 static Handle externalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '/', '.', THREAD); }
169 static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }
170
171 // Conversion
172 static Symbol* as_symbol(Handle java_string, TRAPS);
173 static Symbol* as_symbol_or_null(oop java_string);
174
175 // Testers
176 static bool is_instance(oop obj);
177 static inline bool is_instance_inlined(oop obj);
178
179 // Debugging
180 static void print(oop java_string, outputStream* st);
181 friend class JavaClasses;
182 friend class StringTable;
183 };
184
185
186 // Interface to java.lang.Class objects
187
188 #define CLASS_INJECTED_FIELDS(macro) \
189 macro(java_lang_Class, klass, intptr_signature, false) \
190 macro(java_lang_Class, array_klass, intptr_signature, false) \
191 macro(java_lang_Class, oop_size, int_signature, false) \
192 macro(java_lang_Class, static_oop_field_count, int_signature, false) \
193 macro(java_lang_Class, protection_domain, object_signature, false) \
194 macro(java_lang_Class, signers, object_signature, false)
195
196 class java_lang_Class : AllStatic {
197 friend class VMStructs;
848 enum {
849 hc_referent_offset = 0,
850 hc_queue_offset = 1,
851 hc_next_offset = 2,
852 hc_discovered_offset = 3 // Is not last, see SoftRefs.
853 };
854 enum {
855 hc_static_lock_offset = 0,
856 hc_static_pending_offset = 1
857 };
858
859 static int referent_offset;
860 static int queue_offset;
861 static int next_offset;
862 static int discovered_offset;
863 static int static_lock_offset;
864 static int static_pending_offset;
865 static int number_of_fake_oop_fields;
866
867 // Accessors
868 static inline oop referent(oop ref);
869 static inline void set_referent(oop ref, oop value);
870 static inline void set_referent_raw(oop ref, oop value);
871 static inline HeapWord* referent_addr(oop ref);
872 static inline oop next(oop ref);
873 static inline void set_next(oop ref, oop value);
874 static inline void set_next_raw(oop ref, oop value);
875 static inline HeapWord* next_addr(oop ref);
876 static inline oop discovered(oop ref);
877 static inline void set_discovered(oop ref, oop value);
878 static inline void set_discovered_raw(oop ref, oop value);
879 static inline HeapWord* discovered_addr(oop ref);
880
881 // Accessors for statics
882 static oop pending_list_lock();
883 static oop pending_list();
884
885 static HeapWord* pending_list_lock_addr();
886 static HeapWord* pending_list_addr();
887 };
888
889
890 // Interface to java.lang.ref.SoftReference objects
891
892 class java_lang_ref_SoftReference: public java_lang_ref_Reference {
893 public:
894 enum {
895 // The timestamp is a long field and may need to be adjusted for alignment.
896 hc_timestamp_offset = hc_discovered_offset + 1
897 };
898 enum {
899 hc_static_clock_offset = 0
900 };
|