624 /**
625 * Tells the VM to define a class, without security checks. By default, the
626 * class loader and protection domain come from the caller's class.
627 */
628 public native Class<?> defineClass(String name, byte[] b, int off, int len,
629 ClassLoader loader,
630 ProtectionDomain protectionDomain);
631
632 /**
633 * Defines a class but does not make it known to the class loader or system dictionary.
634 * <p>
635 * For each CP entry, the corresponding CP patch must either be null or have
636 * the a format that matches its tag:
637 * <ul>
638 * <li>Integer, Long, Float, Double: the corresponding wrapper object type from java.lang
639 * <li>Utf8: a string (must have suitable syntax if used as signature or name)
640 * <li>Class: any java.lang.Class object
641 * <li>String: any object (not just a java.lang.String)
642 * <li>InterfaceMethodRef: (NYI) a method handle to invoke on that call site's arguments
643 * </ul>
644 * @params hostClass context for linkage, access control, protection domain, and class loader
645 * @params data bytes of a class file
646 * @params cpPatches where non-null entries exist, they replace corresponding CP entries in data
647 */
648 public native Class<?> defineAnonymousClass(Class<?> hostClass, byte[] data, Object[] cpPatches);
649
650 /**
651 * Allocates an instance but does not run any constructor.
652 * Initializes the class if it has not yet been.
653 */
654 public native Object allocateInstance(Class<?> cls)
655 throws InstantiationException;
656
657 /** Throws the exception without telling the verifier. */
658 public native void throwException(Throwable ee);
659
660 /**
661 * Atomically updates Java variable to {@code x} if it is currently
662 * holding {@code expected}.
663 *
664 * <p>This operation has memory semantics of a {@code volatile} read
665 * and write. Corresponds to C11 atomic_compare_exchange_strong.
666 *
791 * Blocks current thread, returning when a balancing
792 * {@code unpark} occurs, or a balancing {@code unpark} has
793 * already occurred, or the thread is interrupted, or, if not
794 * absolute and time is not zero, the given time nanoseconds have
795 * elapsed, or if absolute, the given deadline in milliseconds
796 * since Epoch has passed, or spuriously (i.e., returning for no
797 * "reason"). Note: This operation is in the Unsafe class only
798 * because {@code unpark} is, so it would be strange to place it
799 * elsewhere.
800 */
801 public native void park(boolean isAbsolute, long time);
802
803 /**
804 * Gets the load average in the system run queue assigned
805 * to the available processors averaged over various periods of time.
806 * This method retrieves the given {@code nelem} samples and
807 * assigns to the elements of the given {@code loadavg} array.
808 * The system imposes a maximum of 3 samples, representing
809 * averages over the last 1, 5, and 15 minutes, respectively.
810 *
811 * @params loadavg an array of double of size nelems
812 * @params nelems the number of samples to be retrieved and
813 * must be 1 to 3.
814 *
815 * @return the number of samples actually retrieved; or -1
816 * if the load average is unobtainable.
817 */
818 public native int getLoadAverage(double[] loadavg, int nelems);
819
820 // The following contain CAS-based Java implementations used on
821 // platforms not supporting native instructions
822
823 /**
824 * Atomically adds the given value to the current value of a field
825 * or array element within the given object {@code o}
826 * at the given {@code offset}.
827 *
828 * @param o object/array to update the field/element in
829 * @param offset field/element offset
830 * @param delta the value to add
831 * @return the previous value
832 * @since 1.8
1091
1092 /**
1093 * Stores a value at some byte offset into a given Java object.
1094 * <p>
1095 * The specification of this method is the same as {@link
1096 * #getLong(Object, long)} except that the offset does not need to
1097 * have been obtained from {@link #objectFieldOffset} on the
1098 * {@link java.lang.reflect.Field} of some Java field. The value
1099 * in memory is raw data, and need not correspond to any Java
1100 * variable. The endianness of the value in memory is the
1101 * endianness of the native platform.
1102 * <p>
1103 * The write will be atomic with respect to the largest power of
1104 * two that divides the GCD of the offset and the storage size.
1105 * For example, putLongUnaligned will make atomic writes of 2-, 4-,
1106 * or 8-byte storage units if the offset is zero mod 2, 4, or 8,
1107 * respectively. There are no other guarantees of atomicity.
1108 * <p>
1109 * 8-byte atomicity is only guaranteed on platforms on which
1110 * support atomic accesses to longs.
1111 * <p>
1112 *
1113 * @param o Java heap object in which the value resides, if any, else
1114 * null
1115 * @param offset The offset in bytes from the start of the object
1116 * @param x the value to store
1117 * @throws RuntimeException No defined exceptions are thrown, not even
1118 * {@link NullPointerException}
1119 * @since 1.9
1120 */
1121 public final void putLongUnaligned(Object o, long offset, long x) {
1122 if ((offset & 7) == 0) {
1123 putLong(o, offset, x);
1124 } else if ((offset & 3) == 0) {
1125 putLongParts(o, offset,
1126 (int)(x >> 0),
1127 (int)(x >>> 32));
1128 } else if ((offset & 1) == 0) {
1129 putLongParts(o, offset,
1130 (short)(x >>> 0),
1131 (short)(x >>> 16),
|
624 /**
625 * Tells the VM to define a class, without security checks. By default, the
626 * class loader and protection domain come from the caller's class.
627 */
628 public native Class<?> defineClass(String name, byte[] b, int off, int len,
629 ClassLoader loader,
630 ProtectionDomain protectionDomain);
631
632 /**
633 * Defines a class but does not make it known to the class loader or system dictionary.
634 * <p>
635 * For each CP entry, the corresponding CP patch must either be null or have
636 * the a format that matches its tag:
637 * <ul>
638 * <li>Integer, Long, Float, Double: the corresponding wrapper object type from java.lang
639 * <li>Utf8: a string (must have suitable syntax if used as signature or name)
640 * <li>Class: any java.lang.Class object
641 * <li>String: any object (not just a java.lang.String)
642 * <li>InterfaceMethodRef: (NYI) a method handle to invoke on that call site's arguments
643 * </ul>
644 * @param hostClass context for linkage, access control, protection domain, and class loader
645 * @param data bytes of a class file
646 * @param cpPatches where non-null entries exist, they replace corresponding CP entries in data
647 */
648 public native Class<?> defineAnonymousClass(Class<?> hostClass, byte[] data, Object[] cpPatches);
649
650 /**
651 * Allocates an instance but does not run any constructor.
652 * Initializes the class if it has not yet been.
653 */
654 public native Object allocateInstance(Class<?> cls)
655 throws InstantiationException;
656
657 /** Throws the exception without telling the verifier. */
658 public native void throwException(Throwable ee);
659
660 /**
661 * Atomically updates Java variable to {@code x} if it is currently
662 * holding {@code expected}.
663 *
664 * <p>This operation has memory semantics of a {@code volatile} read
665 * and write. Corresponds to C11 atomic_compare_exchange_strong.
666 *
791 * Blocks current thread, returning when a balancing
792 * {@code unpark} occurs, or a balancing {@code unpark} has
793 * already occurred, or the thread is interrupted, or, if not
794 * absolute and time is not zero, the given time nanoseconds have
795 * elapsed, or if absolute, the given deadline in milliseconds
796 * since Epoch has passed, or spuriously (i.e., returning for no
797 * "reason"). Note: This operation is in the Unsafe class only
798 * because {@code unpark} is, so it would be strange to place it
799 * elsewhere.
800 */
801 public native void park(boolean isAbsolute, long time);
802
803 /**
804 * Gets the load average in the system run queue assigned
805 * to the available processors averaged over various periods of time.
806 * This method retrieves the given {@code nelem} samples and
807 * assigns to the elements of the given {@code loadavg} array.
808 * The system imposes a maximum of 3 samples, representing
809 * averages over the last 1, 5, and 15 minutes, respectively.
810 *
811 * @param loadavg an array of double of size nelems
812 * @param nelems the number of samples to be retrieved and
813 * must be 1 to 3.
814 *
815 * @return the number of samples actually retrieved; or -1
816 * if the load average is unobtainable.
817 */
818 public native int getLoadAverage(double[] loadavg, int nelems);
819
820 // The following contain CAS-based Java implementations used on
821 // platforms not supporting native instructions
822
823 /**
824 * Atomically adds the given value to the current value of a field
825 * or array element within the given object {@code o}
826 * at the given {@code offset}.
827 *
828 * @param o object/array to update the field/element in
829 * @param offset field/element offset
830 * @param delta the value to add
831 * @return the previous value
832 * @since 1.8
1091
1092 /**
1093 * Stores a value at some byte offset into a given Java object.
1094 * <p>
1095 * The specification of this method is the same as {@link
1096 * #getLong(Object, long)} except that the offset does not need to
1097 * have been obtained from {@link #objectFieldOffset} on the
1098 * {@link java.lang.reflect.Field} of some Java field. The value
1099 * in memory is raw data, and need not correspond to any Java
1100 * variable. The endianness of the value in memory is the
1101 * endianness of the native platform.
1102 * <p>
1103 * The write will be atomic with respect to the largest power of
1104 * two that divides the GCD of the offset and the storage size.
1105 * For example, putLongUnaligned will make atomic writes of 2-, 4-,
1106 * or 8-byte storage units if the offset is zero mod 2, 4, or 8,
1107 * respectively. There are no other guarantees of atomicity.
1108 * <p>
1109 * 8-byte atomicity is only guaranteed on platforms on which
1110 * support atomic accesses to longs.
1111 *
1112 * @param o Java heap object in which the value resides, if any, else
1113 * null
1114 * @param offset The offset in bytes from the start of the object
1115 * @param x the value to store
1116 * @throws RuntimeException No defined exceptions are thrown, not even
1117 * {@link NullPointerException}
1118 * @since 1.9
1119 */
1120 public final void putLongUnaligned(Object o, long offset, long x) {
1121 if ((offset & 7) == 0) {
1122 putLong(o, offset, x);
1123 } else if ((offset & 3) == 0) {
1124 putLongParts(o, offset,
1125 (int)(x >> 0),
1126 (int)(x >>> 32));
1127 } else if ((offset & 1) == 0) {
1128 putLongParts(o, offset,
1129 (short)(x >>> 0),
1130 (short)(x >>> 16),
|