36 // All dependencies on layout of actual Java classes should be kept here.
37 // If the layout of any of the classes above changes the offsets must be adjusted.
38 //
39 // For most classes we hardwire the offsets for performance reasons. In certain
40 // cases (e.g. java.security.AccessControlContext) we compute the offsets at
41 // startup since the layout here differs between JDK1.2 and JDK1.3.
42 //
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 offset_offset;
57 static int count_offset;
58 static int hash_offset;
59
60 static bool initialized;
61
62 static Handle basic_create(int length, TRAPS);
63
64 static void set_offset(oop string, int offset) {
65 assert(initialized, "Must be initialized");
66 if (offset_offset > 0) {
67 string->int_field_put(offset_offset, offset);
68 }
69 }
70 static void set_count( oop string, int count) {
71 assert(initialized, "Must be initialized");
72 if (count_offset > 0) {
73 string->int_field_put(count_offset, count);
74 }
75 }
76
77 public:
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
89 static bool has_offset_field() {
90 assert(initialized, "Must be initialized");
91 return (offset_offset > 0);
92 }
93
94 static bool has_count_field() {
95 assert(initialized, "Must be initialized");
96 return (count_offset > 0);
97 }
98
99 static bool has_hash_field() {
100 assert(initialized, "Must be initialized");
101 return (hash_offset > 0);
102 }
103
104 static int value_offset_in_bytes() {
105 assert(initialized && (value_offset > 0), "Must be initialized");
106 return value_offset;
107 }
108 static int count_offset_in_bytes() {
109 assert(initialized && (count_offset > 0), "Must be initialized");
110 return count_offset;
111 }
112 static int offset_offset_in_bytes() {
113 assert(initialized && (offset_offset > 0), "Must be initialized");
114 return offset_offset;
115 }
116 static int hash_offset_in_bytes() {
117 assert(initialized && (hash_offset > 0), "Must be initialized");
118 return hash_offset;
119 }
120
121 static void set_value_raw(oop string, typeArrayOop buffer) {
122 assert(initialized, "Must be initialized");
123 string->obj_field_put_raw(value_offset, buffer);
124 }
125 static void set_value(oop string, typeArrayOop buffer) {
126 assert(initialized && (value_offset > 0), "Must be initialized");
127 string->obj_field_put(value_offset, (oop)buffer);
128 }
129 static void set_hash(oop string, unsigned int hash) {
130 assert(initialized && (hash_offset > 0), "Must be initialized");
131 string->int_field_put(hash_offset, hash);
132 }
133
134 // Accessors
135 static typeArrayOop value(oop java_string) {
136 assert(initialized && (value_offset > 0), "Must be initialized");
137 assert(is_instance(java_string), "must be java_string");
138 return (typeArrayOop) java_string->obj_field(value_offset);
139 }
140 static unsigned int hash(oop java_string) {
141 assert(initialized && (hash_offset > 0), "Must be initialized");
142 assert(is_instance(java_string), "must be java_string");
143 return java_string->int_field(hash_offset);
144 }
145 static int offset(oop java_string) {
146 assert(initialized, "Must be initialized");
147 assert(is_instance(java_string), "must be java_string");
148 if (offset_offset > 0) {
149 return java_string->int_field(offset_offset);
150 } else {
151 return 0;
152 }
153 }
154 static int length(oop java_string) {
155 assert(initialized, "Must be initialized");
156 assert(is_instance(java_string), "must be java_string");
157 if (count_offset > 0) {
158 return java_string->int_field(count_offset);
159 } else {
160 typeArrayOop value_array = ((typeArrayOop)java_string->obj_field(value_offset));
161 if (value_array == NULL) {
162 return 0;
163 } else {
164 return value_array->length();
165 }
166 }
167 }
168 static int utf8_length(oop java_string);
169
170 // String converters
171 static char* as_utf8_string(oop java_string);
172 static char* as_utf8_string(oop java_string, char* buf, int buflen);
173 static char* as_utf8_string(oop java_string, int start, int len);
174 static char* as_utf8_string(oop java_string, int start, int len, char* buf, int buflen);
175 static char* as_platform_dependent_str(Handle java_string, TRAPS);
176 static jchar* as_unicode_string(oop java_string, int& length, TRAPS);
177 // produce an ascii string with all other values quoted using \u####
178 static char* as_quoted_ascii(oop java_string);
179
180 // Compute the hash value for a java.lang.String object which would
181 // contain the characters passed in.
182 //
183 // As the hash value used by the String object itself, in
184 // String.hashCode(). This value is normally calculated in Java code
185 // in the String.hashCode method(), but is precomputed for String
186 // objects in the shared archive file.
187 // hash P(31) from Kernighan & Ritchie
188 //
189 // For this reason, THIS ALGORITHM MUST MATCH String.hashCode().
190 template <typename T> static unsigned int hash_code(T* s, int len) {
191 unsigned int h = 0;
192 while (len-- > 0) {
193 h = 31*h + (unsigned int) *s;
194 s++;
195 }
196 return h;
197 }
198 static unsigned int hash_code(oop java_string);
199
200 // This is the string hash code used by the StringTable, which may be
201 // the same as String.hashCode or an alternate hash code.
202 static unsigned int hash_string(oop java_string);
203
204 static bool equals(oop java_string, jchar* chars, int len);
205 static bool equals(oop str1, oop str2);
206
207 // Conversion between '.' and '/' formats
208 static Handle externalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '/', '.', THREAD); }
209 static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }
210
211 // Conversion
212 static Symbol* as_symbol(Handle java_string, TRAPS);
213 static Symbol* as_symbol_or_null(oop java_string);
214
215 // Testers
216 static bool is_instance(oop obj);
217 static bool is_instance_inlined(oop obj);
218
434
435 class java_lang_ThreadGroup : AllStatic {
436 private:
437 static int _parent_offset;
438 static int _name_offset;
439 static int _threads_offset;
440 static int _groups_offset;
441 static int _maxPriority_offset;
442 static int _destroyed_offset;
443 static int _daemon_offset;
444 static int _vmAllowSuspension_offset;
445 static int _nthreads_offset;
446 static int _ngroups_offset;
447
448 static void compute_offsets();
449
450 public:
451 // parent ThreadGroup
452 static oop parent(oop java_thread_group);
453 // name
454 static typeArrayOop name(oop java_thread_group);
455 // ("name as oop" accessor is not necessary)
456 // Number of threads in group
457 static int nthreads(oop java_thread_group);
458 // threads
459 static objArrayOop threads(oop java_thread_group);
460 // Number of threads in group
461 static int ngroups(oop java_thread_group);
462 // groups
463 static objArrayOop groups(oop java_thread_group);
464 // maxPriority in group
465 static ThreadPriority maxPriority(oop java_thread_group);
466 // Destroyed
467 static bool is_destroyed(oop java_thread_group);
468 // Daemon
469 static bool is_daemon(oop java_thread_group);
470 // vmAllowSuspension
471 static bool is_vmAllowSuspension(oop java_thread_group);
472 // Debugging
473 friend class JavaClasses;
474 };
|
36 // All dependencies on layout of actual Java classes should be kept here.
37 // If the layout of any of the classes above changes the offsets must be adjusted.
38 //
39 // For most classes we hardwire the offsets for performance reasons. In certain
40 // cases (e.g. java.security.AccessControlContext) we compute the offsets at
41 // startup since the layout here differs between JDK1.2 and JDK1.3.
42 //
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
89 static bool has_hash_field() {
90 assert(initialized, "Must be initialized");
91 return (hash_offset > 0);
92 }
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
182 //
183 // For this reason, THIS ALGORITHM MUST MATCH String.hashCode().
184 static unsigned int hash_code(const jchar* s, int len) {
185 unsigned int h = 0;
186 while (len-- > 0) {
187 h = 31*h + (unsigned int) *s;
188 s++;
189 }
190 return h;
191 }
192
193 static unsigned int hash_code(const jbyte* s, int len) {
194 unsigned int h = 0;
195 while (len-- > 0) {
196 h = 31*h + (((unsigned int) *s) & 0xFF);
197 s++;
198 }
199 return h;
200 }
201
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
439
440 class java_lang_ThreadGroup : AllStatic {
441 private:
442 static int _parent_offset;
443 static int _name_offset;
444 static int _threads_offset;
445 static int _groups_offset;
446 static int _maxPriority_offset;
447 static int _destroyed_offset;
448 static int _daemon_offset;
449 static int _vmAllowSuspension_offset;
450 static int _nthreads_offset;
451 static int _ngroups_offset;
452
453 static void compute_offsets();
454
455 public:
456 // parent ThreadGroup
457 static oop parent(oop java_thread_group);
458 // name
459 static const char* name(oop java_thread_group);
460 // ("name as oop" accessor is not necessary)
461 // Number of threads in group
462 static int nthreads(oop java_thread_group);
463 // threads
464 static objArrayOop threads(oop java_thread_group);
465 // Number of threads in group
466 static int ngroups(oop java_thread_group);
467 // groups
468 static objArrayOop groups(oop java_thread_group);
469 // maxPriority in group
470 static ThreadPriority maxPriority(oop java_thread_group);
471 // Destroyed
472 static bool is_destroyed(oop java_thread_group);
473 // Daemon
474 static bool is_daemon(oop java_thread_group);
475 // vmAllowSuspension
476 static bool is_vmAllowSuspension(oop java_thread_group);
477 // Debugging
478 friend class JavaClasses;
479 };
|