Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8209897

[lworld] JVM_Clone should throw CNSE for value types

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • repo-valhalla
    • repo-valhalla
    • hotspot

      Since value types are not cloneable, JVM_Clone can enforce the check
      rather than doing an assert. javac does not allow Object::clone be called from a value type but it could be called via reflection/method handle or generated bytecode.

        // Check if class of obj supports the Cloneable interface.
        // All arrays are considered to be cloneable (See JLS 20.1.5).
        // All j.l.r.Reference classes are considered non-cloneable.
        if (!klass->is_cloneable() ||
            (klass->is_instance_klass() &&
             InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
          ResourceMark rm(THREAD);
          THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
        }
        assert(!EnableValhalla || !obj->klass()->is_value(), "Clone disallowed on value type");

            dsimms David Simms
            mchung Mandy Chung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: