comparison src/share/vm/prims/jvm.cpp @ 7511:7f062b70a344

Added tag jdk9-b43 for changeset 65a9747147b8
author lana
date Thu, 18 Dec 2014 19:57:49 -0800
parents 0f6100dde08e a12405f751a8
children 4ea7662ddc22
comparison
equal deleted inserted replaced
119:4e8b9f37444c 120:4bca6ee69a22
566 THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name()); 566 THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
567 } 567 }
568 568
569 // Make shallow object copy 569 // Make shallow object copy
570 const int size = obj->size(); 570 const int size = obj->size();
571 oop new_obj = NULL; 571 oop new_obj_oop = NULL;
572 if (obj->is_array()) { 572 if (obj->is_array()) {
573 const int length = ((arrayOop)obj())->length(); 573 const int length = ((arrayOop)obj())->length();
574 new_obj = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL); 574 new_obj_oop = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL);
575 } else { 575 } else {
576 new_obj = CollectedHeap::obj_allocate(klass, size, CHECK_NULL); 576 new_obj_oop = CollectedHeap::obj_allocate(klass, size, CHECK_NULL);
577 } 577 }
578
578 // 4839641 (4840070): We must do an oop-atomic copy, because if another thread 579 // 4839641 (4840070): We must do an oop-atomic copy, because if another thread
579 // is modifying a reference field in the clonee, a non-oop-atomic copy might 580 // is modifying a reference field in the clonee, a non-oop-atomic copy might
580 // be suspended in the middle of copying the pointer and end up with parts 581 // be suspended in the middle of copying the pointer and end up with parts
581 // of two different pointers in the field. Subsequent dereferences will crash. 582 // of two different pointers in the field. Subsequent dereferences will crash.
582 // 4846409: an oop-copy of objects with long or double fields or arrays of same 583 // 4846409: an oop-copy of objects with long or double fields or arrays of same
583 // won't copy the longs/doubles atomically in 32-bit vm's, so we copy jlongs instead 584 // won't copy the longs/doubles atomically in 32-bit vm's, so we copy jlongs instead
584 // of oops. We know objects are aligned on a minimum of an jlong boundary. 585 // of oops. We know objects are aligned on a minimum of an jlong boundary.
585 // The same is true of StubRoutines::object_copy and the various oop_copy 586 // The same is true of StubRoutines::object_copy and the various oop_copy
586 // variants, and of the code generated by the inline_native_clone intrinsic. 587 // variants, and of the code generated by the inline_native_clone intrinsic.
587 assert(MinObjAlignmentInBytes >= BytesPerLong, "objects misaligned"); 588 assert(MinObjAlignmentInBytes >= BytesPerLong, "objects misaligned");
588 Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj, 589 Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj_oop,
589 (size_t)align_object_size(size) / HeapWordsPerLong); 590 (size_t)align_object_size(size) / HeapWordsPerLong);
590 // Clear the header 591 // Clear the header
591 new_obj->init_mark(); 592 new_obj_oop->init_mark();
592 593
593 // Store check (mark entire object and let gc sort it out) 594 // Store check (mark entire object and let gc sort it out)
594 BarrierSet* bs = Universe::heap()->barrier_set(); 595 BarrierSet* bs = Universe::heap()->barrier_set();
595 assert(bs->has_write_region_opt(), "Barrier set does not have write_region"); 596 assert(bs->has_write_region_opt(), "Barrier set does not have write_region");
596 bs->write_region(MemRegion((HeapWord*)new_obj, size)); 597 bs->write_region(MemRegion((HeapWord*)new_obj_oop, size));
598
599 Handle new_obj(THREAD, new_obj_oop);
600 // Special handling for MemberNames. Since they contain Method* metadata, they
601 // must be registered so that RedefineClasses can fix metadata contained in them.
602 if (java_lang_invoke_MemberName::is_instance(new_obj()) &&
603 java_lang_invoke_MemberName::is_method(new_obj())) {
604 Method* method = (Method*)java_lang_invoke_MemberName::vmtarget(new_obj());
605 // MemberName may be unresolved, so doesn't need registration until resolved.
606 if (method != NULL) {
607 methodHandle m(THREAD, method);
608 // This can safepoint and redefine method, so need both new_obj and method
609 // in a handle, for two different reasons. new_obj can move, method can be
610 // deleted if nothing is using it on the stack.
611 m->method_holder()->add_member_name(new_obj());
612 }
613 }
597 614
598 // Caution: this involves a java upcall, so the clone should be 615 // Caution: this involves a java upcall, so the clone should be
599 // "gc-robust" by this stage. 616 // "gc-robust" by this stage.
600 if (klass->has_finalizer()) { 617 if (klass->has_finalizer()) {
601 assert(obj->is_instance(), "should be instanceOop"); 618 assert(obj->is_instance(), "should be instanceOop");
602 new_obj = InstanceKlass::register_finalizer(instanceOop(new_obj), CHECK_NULL); 619 new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL);
603 } 620 new_obj = Handle(THREAD, new_obj_oop);
604 621 }
605 return JNIHandles::make_local(env, oop(new_obj)); 622
623 return JNIHandles::make_local(env, new_obj());
606 JVM_END 624 JVM_END
607 625
608 // java.io.File /////////////////////////////////////////////////////////////// 626 // java.io.File ///////////////////////////////////////////////////////////////
609 627
610 JVM_LEAF(char*, JVM_NativePath(char* path)) 628 JVM_LEAF(char*, JVM_NativePath(char* path))
2592 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) { 2610 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) {
2593 // see bug 4399518, 4417214 2611 // see bug 4399518, 4417214
2594 if ((intptr_t)count <= 0) return -1; 2612 if ((intptr_t)count <= 0) return -1;
2595 2613
2596 int result = vsnprintf(str, count, fmt, args); 2614 int result = vsnprintf(str, count, fmt, args);
2615 // Note: on truncation vsnprintf(3) on Unix returns numbers of
2616 // characters which would have been written had the buffer been large
2617 // enough; on Windows, it returns -1. We handle both cases here and
2618 // always return -1, and perform null termination.
2597 if ((result > 0 && (size_t)result >= count) || result == -1) { 2619 if ((result > 0 && (size_t)result >= count) || result == -1) {
2598 str[count - 1] = '\0'; 2620 str[count - 1] = '\0';
2599 result = -1; 2621 result = -1;
2600 } 2622 }
2601 2623