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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 # include "incls/_precompiled.incl"
26 # include "incls/_constantPoolOop.cpp.incl"
27
28 klassOop constantPoolOopDesc::klass_at_impl(constantPoolHandle this_oop, int which, TRAPS) {
29 // A resolved constantPool entry will contain a klassOop, otherwise a symbolOop.
30 // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and
31 // tag is not updated atomicly.
32 oop entry = *(this_oop->obj_at_addr(which));
33 if (entry->is_klass()) {
34 // Already resolved - return entry.
35 return (klassOop)entry;
36 }
37
38 // Acquire lock on constant oop while doing update. After we get the lock, we check if another object
39 // already has updated the object
40 assert(THREAD->is_Java_thread(), "must be a Java thread");
41 bool do_resolve = false;
42 bool in_error = false;
43
44 symbolHandle name;
45 Handle loader;
46 { ObjectLocker ol(this_oop, THREAD);
47
316 oop entry = *(obj_at_addr(which));
317 if (entry->is_klass()) {
318 // Already resolved - return entry's name.
319 return klassOop(entry)->klass_part()->name();
320 } else {
321 assert(entry->is_symbol(), "must be either symbol or klass");
322 return (symbolOop)entry;
323 }
324 }
325
326 symbolOop constantPoolOopDesc::klass_ref_at_noresolve(int which) {
327 jint ref_index = klass_ref_index_at(which);
328 return klass_at_noresolve(ref_index);
329 }
330
331 char* constantPoolOopDesc::string_at_noresolve(int which) {
332 // Test entry type in case string is resolved while in here.
333 oop entry = *(obj_at_addr(which));
334 if (entry->is_symbol()) {
335 return ((symbolOop)entry)->as_C_string();
336 } else {
337 return java_lang_String::as_utf8_string(entry);
338 }
339 }
340
341
342 symbolOop constantPoolOopDesc::name_ref_at(int which) {
343 jint ref_index = name_and_type_at(name_and_type_ref_index_at(which));
344 int name_index = extract_low_short_from_int(ref_index);
345 return symbol_at(name_index);
346 }
347
348
349 symbolOop constantPoolOopDesc::signature_ref_at(int which) {
350 jint ref_index = name_and_type_at(name_and_type_ref_index_at(which));
351 int signature_index = extract_high_short_from_int(ref_index);
352 return symbol_at(signature_index);
353 }
354
355
356 BasicType constantPoolOopDesc::basic_type_for_signature_at(int which) {
357 return FieldType::basic_type(symbol_at(which));
368
369 oop constantPoolOopDesc::string_at_impl(constantPoolHandle this_oop, int which, TRAPS) {
370 oop entry = *(this_oop->obj_at_addr(which));
371 if (entry->is_symbol()) {
372 ObjectLocker ol(this_oop, THREAD);
373 if (this_oop->tag_at(which).is_unresolved_string()) {
374 // Intern string
375 symbolOop sym = this_oop->unresolved_string_at(which);
376 entry = StringTable::intern(sym, CHECK_(constantPoolOop(NULL)));
377 this_oop->string_at_put(which, entry);
378 } else {
379 // Another thread beat us and interned string, read string from constant pool
380 entry = this_oop->resolved_string_at(which);
381 }
382 }
383 assert(java_lang_String::is_instance(entry), "must be string");
384 return entry;
385 }
386
387
388 bool constantPoolOopDesc::klass_name_at_matches(instanceKlassHandle k,
389 int which) {
390 // Names are interned, so we can compare symbolOops directly
391 symbolOop cp_name = klass_name_at(which);
392 return (cp_name == k->name());
393 }
394
395
396 int constantPoolOopDesc::pre_resolve_shared_klasses(TRAPS) {
397 ResourceMark rm;
398 int count = 0;
399 for (int index = 1; index < tags()->length(); index++) { // Index 0 is unused
400 if (tag_at(index).is_unresolved_string()) {
401 // Intern string
402 symbolOop sym = unresolved_string_at(index);
403 oop entry = StringTable::intern(sym, CHECK_(-1));
404 string_at_put(index, entry);
405 }
406 }
407 return count;
|
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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 # include "incls/_precompiled.incl"
26 # include "incls/_constantPoolOop.cpp.incl"
27
28 void constantPoolOopDesc::set_flag_at(FlagBit fb) {
29 const int MAX_STATE_CHANGES = 2;
30 for (int i = MAX_STATE_CHANGES + 10; i > 0; i--) {
31 int oflags = _flags;
32 int nflags = oflags | (1 << (int)fb);
33 if (Atomic::cmpxchg(nflags, &_flags, oflags) == oflags)
34 return;
35 }
36 assert(false, "failed to cmpxchg flags");
37 _flags |= (1 << (int)fb); // better than nothing
38 }
39
40 klassOop constantPoolOopDesc::klass_at_impl(constantPoolHandle this_oop, int which, TRAPS) {
41 // A resolved constantPool entry will contain a klassOop, otherwise a symbolOop.
42 // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and
43 // tag is not updated atomicly.
44 oop entry = *(this_oop->obj_at_addr(which));
45 if (entry->is_klass()) {
46 // Already resolved - return entry.
47 return (klassOop)entry;
48 }
49
50 // Acquire lock on constant oop while doing update. After we get the lock, we check if another object
51 // already has updated the object
52 assert(THREAD->is_Java_thread(), "must be a Java thread");
53 bool do_resolve = false;
54 bool in_error = false;
55
56 symbolHandle name;
57 Handle loader;
58 { ObjectLocker ol(this_oop, THREAD);
59
328 oop entry = *(obj_at_addr(which));
329 if (entry->is_klass()) {
330 // Already resolved - return entry's name.
331 return klassOop(entry)->klass_part()->name();
332 } else {
333 assert(entry->is_symbol(), "must be either symbol or klass");
334 return (symbolOop)entry;
335 }
336 }
337
338 symbolOop constantPoolOopDesc::klass_ref_at_noresolve(int which) {
339 jint ref_index = klass_ref_index_at(which);
340 return klass_at_noresolve(ref_index);
341 }
342
343 char* constantPoolOopDesc::string_at_noresolve(int which) {
344 // Test entry type in case string is resolved while in here.
345 oop entry = *(obj_at_addr(which));
346 if (entry->is_symbol()) {
347 return ((symbolOop)entry)->as_C_string();
348 } else if (java_lang_String::is_instance(entry)) {
349 return java_lang_String::as_utf8_string(entry);
350 } else {
351 return (char*)"<pseudo-string>";
352 }
353 }
354
355
356 symbolOop constantPoolOopDesc::name_ref_at(int which) {
357 jint ref_index = name_and_type_at(name_and_type_ref_index_at(which));
358 int name_index = extract_low_short_from_int(ref_index);
359 return symbol_at(name_index);
360 }
361
362
363 symbolOop constantPoolOopDesc::signature_ref_at(int which) {
364 jint ref_index = name_and_type_at(name_and_type_ref_index_at(which));
365 int signature_index = extract_high_short_from_int(ref_index);
366 return symbol_at(signature_index);
367 }
368
369
370 BasicType constantPoolOopDesc::basic_type_for_signature_at(int which) {
371 return FieldType::basic_type(symbol_at(which));
382
383 oop constantPoolOopDesc::string_at_impl(constantPoolHandle this_oop, int which, TRAPS) {
384 oop entry = *(this_oop->obj_at_addr(which));
385 if (entry->is_symbol()) {
386 ObjectLocker ol(this_oop, THREAD);
387 if (this_oop->tag_at(which).is_unresolved_string()) {
388 // Intern string
389 symbolOop sym = this_oop->unresolved_string_at(which);
390 entry = StringTable::intern(sym, CHECK_(constantPoolOop(NULL)));
391 this_oop->string_at_put(which, entry);
392 } else {
393 // Another thread beat us and interned string, read string from constant pool
394 entry = this_oop->resolved_string_at(which);
395 }
396 }
397 assert(java_lang_String::is_instance(entry), "must be string");
398 return entry;
399 }
400
401
402 bool constantPoolOopDesc::is_pseudo_string_at(int which) {
403 oop entry = *(obj_at_addr(which));
404 if (entry->is_symbol())
405 // Not yet resolved, but it will resolve to a string.
406 return false;
407 else if (java_lang_String::is_instance(entry))
408 return false; // actually, it might be a non-interned or non-perm string
409 else
410 // truly pseudo
411 return true;
412 }
413
414
415 bool constantPoolOopDesc::klass_name_at_matches(instanceKlassHandle k,
416 int which) {
417 // Names are interned, so we can compare symbolOops directly
418 symbolOop cp_name = klass_name_at(which);
419 return (cp_name == k->name());
420 }
421
422
423 int constantPoolOopDesc::pre_resolve_shared_klasses(TRAPS) {
424 ResourceMark rm;
425 int count = 0;
426 for (int index = 1; index < tags()->length(); index++) { // Index 0 is unused
427 if (tag_at(index).is_unresolved_string()) {
428 // Intern string
429 symbolOop sym = unresolved_string_at(index);
430 oop entry = StringTable::intern(sym, CHECK_(-1));
431 string_at_put(index, entry);
432 }
433 }
434 return count;
|