$ java -XX:+UnlockDiagnosticVMOptions -XX:+PrintFlagsFinal -version
Dates aren't what they used to be
21 час назад
$ java -XX:+UnlockDiagnosticVMOptions -XX:+PrintFlagsFinal -version
/**
* Sets all bytes in a given block of memory to a copy of another
* block.
*
* This method determines each block's base address by means of two parameters,
* and so it provides (in effect) a double-register addressing mode,
* as discussed in {@link #getInt(Object,long)}. When the object reference is null,
* the offset supplies an absolute base address.
*
* The transfers are in coherent (atomic) units of a size determined
* by the address and length parameters. If the effective addresses and
* length are all even modulo 8, the transfer takes place in 'long' units.
* If the effective addresses and length are (resp.) even modulo 4 or 2,
* the transfer takes place in units of 'int' or 'short'.
*
* @since 1.7
*/
uintptr_t bits = (uintptr_t) src | (uintptr_t) dst | (uintptr_t) size;
if (bits % sizeof(jlong) == 0) {
Copy::conjoint_jlongs_atomic((jlong*) src, (jlong*) dst, size / sizeof(jlong));
} else if (bits % sizeof(jint) == 0) {
Copy::conjoint_jints_atomic((jint*) src, (jint*) dst, size / sizeof(jint));
} else if (bits % sizeof(jshort) == 0) {
Copy::conjoint_jshorts_atomic((jshort*) src, (jshort*) dst, size / sizeof(jshort));
} else {
// Not aligned, so no need to be atomic.
Copy::conjoint_jbytes((void*) src, (void*) dst, size);
}
Если кратко, то bits тогда и только тогда будет кратен размеру long, когда и адрес источника, и адрес цели, и длина блока будут кратны размеру long.
Benchmark Mode Samples Score Error Units copyMemory253Bytes avgt 15 13.023 ± 0.376 ns/op copyMemory253BytesOffset3 avgt 15 13.189 ± 0.512 ns/op copyMemory256Bytes avgt 15 11.091 ± 0.304 ns/op copyMemory256BytesOffset7 avgt 15 13.185 ± 0.066 ns/op copyMemory27Bytes avgt 15 9.034 ± 0.058 ns/op copyMemory32Bytes avgt 15 5.567 ± 0.154 ns/op copyMemory32BytesOffset3 avgt 15 7.779 ± 0.080 ns/op copyMemory4Bytes avgt 15 6.801 ± 0.068 ns/op copyMemory4BytesOffset3 avgt 15 7.760 ± 0.091 ns/op copyMemory8Bytes avgt 15 6.763 ± 0.044 ns/op copyMemory8BytesOffset1 avgt 15 8.398 ± 0.154 ns/op copyMemory8BytesOffset3 avgt 15 8.368 ± 0.083 ns/op copyMemory8BytesOffset5 avgt 15 8.396 ± 0.079 ns/op readByteOffset0 avgt 15 3.067 ± 0.153 ns/op readByteOffset3 avgt 15 3.024 ± 0.044 ns/op readIntOffset0 avgt 15 3.001 ± 0.037 ns/op readIntOffset3 avgt 15 3.051 ± 0.150 ns/op readLongOffset0 avgt 15 2.997 ± 0.042 ns/op readLongOffset3 avgt 15 2.993 ± 0.056 ns/opи для 1 нитки
Benchmark Mode Samples Score Error Units copyMemory253Bytes avgt 15 13.392 ± 0.580 ns/op copyMemory253BytesOffset3 avgt 15 12.903 ± 0.304 ns/op copyMemory256Bytes avgt 15 11.195 ± 0.405 ns/op copyMemory256BytesOffset7 avgt 15 13.446 ± 0.422 ns/op copyMemory27Bytes avgt 15 9.136 ± 0.266 ns/op copyMemory32Bytes avgt 15 5.513 ± 0.190 ns/op copyMemory32BytesOffset3 avgt 15 7.830 ± 0.273 ns/op copyMemory4Bytes avgt 15 6.826 ± 0.204 ns/op copyMemory4BytesOffset3 avgt 15 7.757 ± 0.223 ns/op copyMemory8Bytes avgt 15 6.897 ± 0.221 ns/op copyMemory8BytesOffset1 avgt 15 8.534 ± 0.276 ns/op copyMemory8BytesOffset3 avgt 15 8.482 ± 0.285 ns/op copyMemory8BytesOffset5 avgt 15 8.403 ± 0.262 ns/op readByteOffset0 avgt 15 2.971 ± 0.104 ns/op readByteOffset3 avgt 15 3.009 ± 0.115 ns/op readIntOffset0 avgt 15 3.001 ± 0.125 ns/op readIntOffset3 avgt 15 3.032 ± 0.113 ns/op readLongOffset0 avgt 15 3.010 ± 0.100 ns/op readLongOffset3 avgt 15 3.060 ± 0.094 ns/opТ.е действительно для копирования очень важно, чтобы всё было по восьмерке, тогда как для чтения это не имеет значения. ... meten is weten // голл. поговорка: измерение это знание