comparison src/share/vm/classfile/javaClasses.cpp @ 10408:836a62f43af9

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author Doug Simon <doug.simon@oracle.com>
date Wed, 19 Jun 2013 10:45:56 +0200
parents 3ac7d10a6572 f2110083203d
children 6b0fd0964b87
comparison
equal deleted inserted replaced
10086:e0fb8a213650 10408:836a62f43af9
313 to_buffer->char_at_put(index, c); 313 to_buffer->char_at_put(index, c);
314 } 314 }
315 return string; 315 return string;
316 } 316 }
317 317
318 jchar* java_lang_String::as_unicode_string(oop java_string, int& length) { 318 jchar* java_lang_String::as_unicode_string(oop java_string, int& length, TRAPS) {
319 typeArrayOop value = java_lang_String::value(java_string); 319 typeArrayOop value = java_lang_String::value(java_string);
320 int offset = java_lang_String::offset(java_string); 320 int offset = java_lang_String::offset(java_string);
321 length = java_lang_String::length(java_string); 321 length = java_lang_String::length(java_string);
322 322
323 jchar* result = NEW_RESOURCE_ARRAY(jchar, length); 323 jchar* result = NEW_RESOURCE_ARRAY_RETURN_NULL(jchar, length);
324 for (int index = 0; index < length; index++) { 324 if (result != NULL) {
325 result[index] = value->char_at(index + offset); 325 for (int index = 0; index < length; index++) {
326 result[index] = value->char_at(index + offset);
327 }
328 } else {
329 THROW_MSG_0(vmSymbols::java_lang_OutOfMemoryError(), "could not allocate Unicode string");
326 } 330 }
327 return result; 331 return result;
328 } 332 }
329 333
330 unsigned int java_lang_String::hash_code(oop java_string) { 334 unsigned int java_lang_String::hash_code(oop java_string) {
506 void java_lang_Class::fixup_mirror(KlassHandle k, TRAPS) { 510 void java_lang_Class::fixup_mirror(KlassHandle k, TRAPS) {
507 assert(InstanceMirrorKlass::offset_of_static_fields() != 0, "must have been computed already"); 511 assert(InstanceMirrorKlass::offset_of_static_fields() != 0, "must have been computed already");
508 512
509 // If the offset was read from the shared archive, it was fixed up already 513 // If the offset was read from the shared archive, it was fixed up already
510 if (!k->is_shared()) { 514 if (!k->is_shared()) {
511 if (k->oop_is_instance()) { 515 if (k->oop_is_instance()) {
512 // During bootstrap, java.lang.Class wasn't loaded so static field 516 // During bootstrap, java.lang.Class wasn't loaded so static field
513 // offsets were computed without the size added it. Go back and 517 // offsets were computed without the size added it. Go back and
514 // update all the static field offsets to included the size. 518 // update all the static field offsets to included the size.
515 for (JavaFieldStream fs(InstanceKlass::cast(k())); !fs.done(); fs.next()) { 519 for (JavaFieldStream fs(InstanceKlass::cast(k())); !fs.done(); fs.next()) {
516 if (fs.access_flags().is_static()) { 520 if (fs.access_flags().is_static()) {
517 int real_offset = fs.offset() + InstanceMirrorKlass::offset_of_static_fields(); 521 int real_offset = fs.offset() + InstanceMirrorKlass::offset_of_static_fields();
518 fs.set_offset(real_offset); 522 fs.set_offset(real_offset);
523 }
519 } 524 }
520 } 525 }
521 } 526 }
522 } 527 create_mirror(k, Handle(NULL), CHECK);
523 create_mirror(k, CHECK); 528 }
524 } 529
525 530 oop java_lang_Class::create_mirror(KlassHandle k, Handle protection_domain, TRAPS) {
526 oop java_lang_Class::create_mirror(KlassHandle k, TRAPS) {
527 assert(k->java_mirror() == NULL, "should only assign mirror once"); 531 assert(k->java_mirror() == NULL, "should only assign mirror once");
528 // Use this moment of initialization to cache modifier_flags also, 532 // Use this moment of initialization to cache modifier_flags also,
529 // to support Class.getModifiers(). Instance classes recalculate 533 // to support Class.getModifiers(). Instance classes recalculate
530 // the cached flags after the class file is parsed, but before the 534 // the cached flags after the class file is parsed, but before the
531 // class is put into the system dictionary. 535 // class is put into the system dictionary.
557 // Two-way link between the array klass and its component mirror: 561 // Two-way link between the array klass and its component mirror:
558 ArrayKlass::cast(k())->set_component_mirror(comp_mirror()); 562 ArrayKlass::cast(k())->set_component_mirror(comp_mirror());
559 set_array_klass(comp_mirror(), k()); 563 set_array_klass(comp_mirror(), k());
560 } else { 564 } else {
561 assert(k->oop_is_instance(), "Must be"); 565 assert(k->oop_is_instance(), "Must be");
566
567 // Allocate a simple java object for a lock.
568 // This needs to be a java object because during class initialization
569 // it can be held across a java call.
570 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK_NULL);
571 set_init_lock(mirror(), r);
572
573 // Set protection domain also
574 set_protection_domain(mirror(), protection_domain());
575
562 // Initialize static fields 576 // Initialize static fields
563 InstanceKlass::cast(k())->do_local_static_fields(&initialize_static_field, CHECK_NULL); 577 InstanceKlass::cast(k())->do_local_static_fields(&initialize_static_field, CHECK_NULL);
564 } 578 }
565 return mirror(); 579 return mirror();
566 } else { 580 } else {
590 } 604 }
591 void java_lang_Class::set_static_oop_field_count(oop java_class, int size) { 605 void java_lang_Class::set_static_oop_field_count(oop java_class, int size) {
592 assert(_static_oop_field_count_offset != 0, "must be set"); 606 assert(_static_oop_field_count_offset != 0, "must be set");
593 java_class->int_field_put(_static_oop_field_count_offset, size); 607 java_class->int_field_put(_static_oop_field_count_offset, size);
594 } 608 }
609
610 oop java_lang_Class::protection_domain(oop java_class) {
611 assert(_protection_domain_offset != 0, "must be set");
612 return java_class->obj_field(_protection_domain_offset);
613 }
614 void java_lang_Class::set_protection_domain(oop java_class, oop pd) {
615 assert(_protection_domain_offset != 0, "must be set");
616 java_class->obj_field_put(_protection_domain_offset, pd);
617 }
618
619 oop java_lang_Class::init_lock(oop java_class) {
620 assert(_init_lock_offset != 0, "must be set");
621 return java_class->obj_field(_init_lock_offset);
622 }
623 void java_lang_Class::set_init_lock(oop java_class, oop init_lock) {
624 assert(_init_lock_offset != 0, "must be set");
625 java_class->obj_field_put(_init_lock_offset, init_lock);
626 }
627
628 objArrayOop java_lang_Class::signers(oop java_class) {
629 assert(_signers_offset != 0, "must be set");
630 return (objArrayOop)java_class->obj_field(_signers_offset);
631 }
632 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
633 assert(_signers_offset != 0, "must be set");
634 java_class->obj_field_put(_signers_offset, (oop)signers);
635 }
636
595 637
596 oop java_lang_Class::create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS) { 638 oop java_lang_Class::create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS) {
597 // This should be improved by adding a field at the Java level or by 639 // This should be improved by adding a field at the Java level or by
598 // introducing a new VM klass (see comment in ClassFileParser) 640 // introducing a new VM klass (see comment in ClassFileParser)
599 oop java_class = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(NULL, CHECK_0); 641 oop java_class = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(NULL, CHECK_0);
923 } 965 }
924 } 966 }
925 967
926 // Read thread status value from threadStatus field in java.lang.Thread java class. 968 // Read thread status value from threadStatus field in java.lang.Thread java class.
927 java_lang_Thread::ThreadStatus java_lang_Thread::get_thread_status(oop java_thread) { 969 java_lang_Thread::ThreadStatus java_lang_Thread::get_thread_status(oop java_thread) {
928 assert(Thread::current()->is_VM_thread() || 970 assert(Thread::current()->is_Watcher_thread() || Thread::current()->is_VM_thread() ||
929 JavaThread::current()->thread_state() == _thread_in_vm, 971 JavaThread::current()->thread_state() == _thread_in_vm,
930 "Java Thread is not running in vm"); 972 "Java Thread is not running in vm");
931 // The threadStatus is only present starting in 1.5 973 // The threadStatus is only present starting in 1.5
932 if (_thread_status_offset > 0) { 974 if (_thread_status_offset > 0) {
933 return (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset); 975 return (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset);
2629 Metadata* java_lang_invoke_MemberName::vmtarget(oop mname) { 2671 Metadata* java_lang_invoke_MemberName::vmtarget(oop mname) {
2630 assert(is_instance(mname), "wrong type"); 2672 assert(is_instance(mname), "wrong type");
2631 return (Metadata*)mname->address_field(_vmtarget_offset); 2673 return (Metadata*)mname->address_field(_vmtarget_offset);
2632 } 2674 }
2633 2675
2676 #if INCLUDE_JVMTI
2677 // Can be executed on VM thread only
2678 void java_lang_invoke_MemberName::adjust_vmtarget(oop mname, Metadata* ref) {
2679 assert((is_instance(mname) && (flags(mname) & (MN_IS_METHOD | MN_IS_CONSTRUCTOR)) > 0), "wrong type");
2680 assert(Thread::current()->is_VM_thread(), "not VM thread");
2681 mname->address_field_put(_vmtarget_offset, (address)ref);
2682 }
2683 #endif // INCLUDE_JVMTI
2684
2634 void java_lang_invoke_MemberName::set_vmtarget(oop mname, Metadata* ref) { 2685 void java_lang_invoke_MemberName::set_vmtarget(oop mname, Metadata* ref) {
2635 assert(is_instance(mname), "wrong type"); 2686 assert(is_instance(mname), "wrong type");
2636 // check the type of the vmtarget 2687 // check the type of the vmtarget
2637 oop dependency = NULL; 2688 oop dependency = NULL;
2638 if (ref != NULL) { 2689 if (ref != NULL) {
2925 2976
2926 int java_lang_Class::_klass_offset; 2977 int java_lang_Class::_klass_offset;
2927 int java_lang_Class::_array_klass_offset; 2978 int java_lang_Class::_array_klass_offset;
2928 int java_lang_Class::_oop_size_offset; 2979 int java_lang_Class::_oop_size_offset;
2929 int java_lang_Class::_static_oop_field_count_offset; 2980 int java_lang_Class::_static_oop_field_count_offset;
2981 int java_lang_Class::_protection_domain_offset;
2982 int java_lang_Class::_init_lock_offset;
2983 int java_lang_Class::_signers_offset;
2930 #ifdef GRAAL 2984 #ifdef GRAAL
2931 int java_lang_Class::_graal_mirror_offset; 2985 int java_lang_Class::_graal_mirror_offset;
2932 #endif 2986 #endif
2933 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL; 2987 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL;
2934 int java_lang_Throwable::backtrace_offset; 2988 int java_lang_Throwable::backtrace_offset;