src/share/vm/runtime/stubRoutines.cpp

changeset 1958
d93949c5bdcc
parent 1907
c18cbe5936b8
child 2103
3e8fbc61cee8
child 2118
d6f45b55c972
     1.1 --- a/src/share/vm/runtime/stubRoutines.cpp	Wed Jun 09 18:50:45 2010 -0700
     1.2 +++ b/src/share/vm/runtime/stubRoutines.cpp	Thu Jun 10 13:04:20 2010 -0700
     1.3 @@ -135,28 +135,32 @@
     1.4  static void test_arraycopy_func(address func, int alignment) {
     1.5    int v = 0xcc;
     1.6    int v2 = 0x11;
     1.7 -  jlong lbuffer[2];
     1.8 -  jlong lbuffer2[2];
     1.9 -  address buffer  = (address) lbuffer;
    1.10 -  address buffer2 = (address) lbuffer2;
    1.11 +  jlong lbuffer[8];
    1.12 +  jlong lbuffer2[8];
    1.13 +  address fbuffer  = (address) lbuffer;
    1.14 +  address fbuffer2 = (address) lbuffer2;
    1.15    unsigned int i;
    1.16    for (i = 0; i < sizeof(lbuffer); i++) {
    1.17 -    buffer[i] = v; buffer2[i] = v2;
    1.18 +    fbuffer[i] = v; fbuffer2[i] = v2;
    1.19    }
    1.20 +  // C++ does not guarantee jlong[] array alignment to 8 bytes.
    1.21 +  // Use middle of array to check that memory before it is not modified.
    1.22 +  address buffer  = (address) round_to((intptr_t)&lbuffer[4], BytesPerLong);
    1.23 +  address buffer2 = (address) round_to((intptr_t)&lbuffer2[4], BytesPerLong);
    1.24    // do an aligned copy
    1.25    ((arraycopy_fn)func)(buffer, buffer2, 0);
    1.26    for (i = 0; i < sizeof(lbuffer); i++) {
    1.27 -    assert(buffer[i] == v && buffer2[i] == v2, "shouldn't have copied anything");
    1.28 +    assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
    1.29    }
    1.30    // adjust destination alignment
    1.31    ((arraycopy_fn)func)(buffer, buffer2 + alignment, 0);
    1.32    for (i = 0; i < sizeof(lbuffer); i++) {
    1.33 -    assert(buffer[i] == v && buffer2[i] == v2, "shouldn't have copied anything");
    1.34 +    assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
    1.35    }
    1.36    // adjust source alignment
    1.37    ((arraycopy_fn)func)(buffer + alignment, buffer2, 0);
    1.38    for (i = 0; i < sizeof(lbuffer); i++) {
    1.39 -    assert(buffer[i] == v && buffer2[i] == v2, "shouldn't have copied anything");
    1.40 +    assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
    1.41    }
    1.42  }
    1.43  #endif
    1.44 @@ -183,7 +187,7 @@
    1.45    test_arraycopy_func(arrayof_##type##_arraycopy(),          sizeof(HeapWord)); \
    1.46    test_arraycopy_func(arrayof_##type##_disjoint_arraycopy(), sizeof(HeapWord))
    1.47  
    1.48 -  // Make sure all the arraycopy stubs properly handle zeros
    1.49 +  // Make sure all the arraycopy stubs properly handle zero count
    1.50    TEST_ARRAYCOPY(jbyte);
    1.51    TEST_ARRAYCOPY(jshort);
    1.52    TEST_ARRAYCOPY(jint);
    1.53 @@ -191,6 +195,25 @@
    1.54  
    1.55  #undef TEST_ARRAYCOPY
    1.56  
    1.57 +#define TEST_COPYRTN(type) \
    1.58 +  test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::conjoint_##type##s_atomic),  sizeof(type)); \
    1.59 +  test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::arrayof_conjoint_##type##s), (int)MAX2(sizeof(HeapWord), sizeof(type)))
    1.60 +
    1.61 +  // Make sure all the copy runtime routines properly handle zero count
    1.62 +  TEST_COPYRTN(jbyte);
    1.63 +  TEST_COPYRTN(jshort);
    1.64 +  TEST_COPYRTN(jint);
    1.65 +  TEST_COPYRTN(jlong);
    1.66 +
    1.67 +#undef TEST_COPYRTN
    1.68 +
    1.69 +  test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::conjoint_words), sizeof(HeapWord));
    1.70 +  test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::disjoint_words), sizeof(HeapWord));
    1.71 +  test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::disjoint_words_atomic), sizeof(HeapWord));
    1.72 +  // Aligned to BytesPerLong
    1.73 +  test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_conjoint_words), sizeof(jlong));
    1.74 +  test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_disjoint_words), sizeof(jlong));
    1.75 +
    1.76  #endif
    1.77  }
    1.78  
    1.79 @@ -221,15 +244,13 @@
    1.80  #ifndef PRODUCT
    1.81    SharedRuntime::_jbyte_array_copy_ctr++;      // Slow-path byte array copy
    1.82  #endif // !PRODUCT
    1.83 -  assert(count != 0, "count should be non-zero");
    1.84 -  Copy::conjoint_bytes_atomic(src, dest, count);
    1.85 +  Copy::conjoint_jbytes_atomic(src, dest, count);
    1.86  JRT_END
    1.87  
    1.88  JRT_LEAF(void, StubRoutines::jshort_copy(jshort* src, jshort* dest, size_t count))
    1.89  #ifndef PRODUCT
    1.90    SharedRuntime::_jshort_array_copy_ctr++;     // Slow-path short/char array copy
    1.91  #endif // !PRODUCT
    1.92 -  assert(count != 0, "count should be non-zero");
    1.93    Copy::conjoint_jshorts_atomic(src, dest, count);
    1.94  JRT_END
    1.95  
    1.96 @@ -237,7 +258,6 @@
    1.97  #ifndef PRODUCT
    1.98    SharedRuntime::_jint_array_copy_ctr++;       // Slow-path int/float array copy
    1.99  #endif // !PRODUCT
   1.100 -  assert(count != 0, "count should be non-zero");
   1.101    Copy::conjoint_jints_atomic(src, dest, count);
   1.102  JRT_END
   1.103  
   1.104 @@ -245,7 +265,6 @@
   1.105  #ifndef PRODUCT
   1.106    SharedRuntime::_jlong_array_copy_ctr++;      // Slow-path long/double array copy
   1.107  #endif // !PRODUCT
   1.108 -  assert(count != 0, "count should be non-zero");
   1.109    Copy::conjoint_jlongs_atomic(src, dest, count);
   1.110  JRT_END
   1.111  
   1.112 @@ -263,15 +282,13 @@
   1.113  #ifndef PRODUCT
   1.114    SharedRuntime::_jbyte_array_copy_ctr++;      // Slow-path byte array copy
   1.115  #endif // !PRODUCT
   1.116 -  assert(count != 0, "count should be non-zero");
   1.117 -  Copy::arrayof_conjoint_bytes(src, dest, count);
   1.118 +  Copy::arrayof_conjoint_jbytes(src, dest, count);
   1.119  JRT_END
   1.120  
   1.121  JRT_LEAF(void, StubRoutines::arrayof_jshort_copy(HeapWord* src, HeapWord* dest, size_t count))
   1.122  #ifndef PRODUCT
   1.123    SharedRuntime::_jshort_array_copy_ctr++;     // Slow-path short/char array copy
   1.124  #endif // !PRODUCT
   1.125 -  assert(count != 0, "count should be non-zero");
   1.126    Copy::arrayof_conjoint_jshorts(src, dest, count);
   1.127  JRT_END
   1.128  
   1.129 @@ -279,7 +296,6 @@
   1.130  #ifndef PRODUCT
   1.131    SharedRuntime::_jint_array_copy_ctr++;       // Slow-path int/float array copy
   1.132  #endif // !PRODUCT
   1.133 -  assert(count != 0, "count should be non-zero");
   1.134    Copy::arrayof_conjoint_jints(src, dest, count);
   1.135  JRT_END
   1.136  
   1.137 @@ -287,7 +303,6 @@
   1.138  #ifndef PRODUCT
   1.139    SharedRuntime::_jlong_array_copy_ctr++;       // Slow-path int/float array copy
   1.140  #endif // !PRODUCT
   1.141 -  assert(count != 0, "count should be non-zero");
   1.142    Copy::arrayof_conjoint_jlongs(src, dest, count);
   1.143  JRT_END
   1.144  

mercurial