src/share/vm/runtime/stubRoutines.cpp

Fri, 27 Aug 2010 17:33:49 -0700

author
never
date
Fri, 27 Aug 2010 17:33:49 -0700
changeset 2118
d6f45b55c972
parent 1958
d93949c5bdcc
child 2119
14197af1010e
permissions
-rw-r--r--

4809552: Optimize Arrays.fill(...)
Reviewed-by: kvn

     1 /*
     2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #include "incls/_precompiled.incl"
    26 #include "incls/_stubRoutines.cpp.incl"
    29 // Implementation of StubRoutines - for a description
    30 // of how to extend it, see the header file.
    32 // Class Variables
    34 BufferBlob* StubRoutines::_code1                                = NULL;
    35 BufferBlob* StubRoutines::_code2                                = NULL;
    37 address StubRoutines::_call_stub_return_address                 = NULL;
    38 address StubRoutines::_call_stub_entry                          = NULL;
    40 address StubRoutines::_catch_exception_entry                    = NULL;
    41 address StubRoutines::_forward_exception_entry                  = NULL;
    42 address StubRoutines::_throw_AbstractMethodError_entry          = NULL;
    43 address StubRoutines::_throw_IncompatibleClassChangeError_entry = NULL;
    44 address StubRoutines::_throw_ArithmeticException_entry          = NULL;
    45 address StubRoutines::_throw_NullPointerException_entry         = NULL;
    46 address StubRoutines::_throw_NullPointerException_at_call_entry = NULL;
    47 address StubRoutines::_throw_StackOverflowError_entry           = NULL;
    48 address StubRoutines::_handler_for_unsafe_access_entry          = NULL;
    49 jint    StubRoutines::_verify_oop_count                         = 0;
    50 address StubRoutines::_verify_oop_subroutine_entry              = NULL;
    51 address StubRoutines::_atomic_xchg_entry                        = NULL;
    52 address StubRoutines::_atomic_xchg_ptr_entry                    = NULL;
    53 address StubRoutines::_atomic_store_entry                       = NULL;
    54 address StubRoutines::_atomic_store_ptr_entry                   = NULL;
    55 address StubRoutines::_atomic_cmpxchg_entry                     = NULL;
    56 address StubRoutines::_atomic_cmpxchg_ptr_entry                 = NULL;
    57 address StubRoutines::_atomic_cmpxchg_long_entry                = NULL;
    58 address StubRoutines::_atomic_add_entry                         = NULL;
    59 address StubRoutines::_atomic_add_ptr_entry                     = NULL;
    60 address StubRoutines::_fence_entry                              = NULL;
    61 address StubRoutines::_d2i_wrapper                              = NULL;
    62 address StubRoutines::_d2l_wrapper                              = NULL;
    64 jint    StubRoutines::_fpu_cntrl_wrd_std                        = 0;
    65 jint    StubRoutines::_fpu_cntrl_wrd_24                         = 0;
    66 jint    StubRoutines::_fpu_cntrl_wrd_64                         = 0;
    67 jint    StubRoutines::_fpu_cntrl_wrd_trunc                      = 0;
    68 jint    StubRoutines::_mxcsr_std                                = 0;
    69 jint    StubRoutines::_fpu_subnormal_bias1[3]                   = { 0, 0, 0 };
    70 jint    StubRoutines::_fpu_subnormal_bias2[3]                   = { 0, 0, 0 };
    72 // Compiled code entry points default values
    73 // The dafault functions don't have separate disjoint versions.
    74 address StubRoutines::_jbyte_arraycopy          = CAST_FROM_FN_PTR(address, StubRoutines::jbyte_copy);
    75 address StubRoutines::_jshort_arraycopy         = CAST_FROM_FN_PTR(address, StubRoutines::jshort_copy);
    76 address StubRoutines::_jint_arraycopy           = CAST_FROM_FN_PTR(address, StubRoutines::jint_copy);
    77 address StubRoutines::_jlong_arraycopy          = CAST_FROM_FN_PTR(address, StubRoutines::jlong_copy);
    78 address StubRoutines::_oop_arraycopy            = CAST_FROM_FN_PTR(address, StubRoutines::oop_copy);
    79 address StubRoutines::_jbyte_disjoint_arraycopy          = CAST_FROM_FN_PTR(address, StubRoutines::jbyte_copy);
    80 address StubRoutines::_jshort_disjoint_arraycopy         = CAST_FROM_FN_PTR(address, StubRoutines::jshort_copy);
    81 address StubRoutines::_jint_disjoint_arraycopy           = CAST_FROM_FN_PTR(address, StubRoutines::jint_copy);
    82 address StubRoutines::_jlong_disjoint_arraycopy          = CAST_FROM_FN_PTR(address, StubRoutines::jlong_copy);
    83 address StubRoutines::_oop_disjoint_arraycopy            = CAST_FROM_FN_PTR(address, StubRoutines::oop_copy);
    85 address StubRoutines::_arrayof_jbyte_arraycopy  = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_jbyte_copy);
    86 address StubRoutines::_arrayof_jshort_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_jshort_copy);
    87 address StubRoutines::_arrayof_jint_arraycopy   = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_jint_copy);
    88 address StubRoutines::_arrayof_jlong_arraycopy  = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_jlong_copy);
    89 address StubRoutines::_arrayof_oop_arraycopy    = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_oop_copy);
    90 address StubRoutines::_arrayof_jbyte_disjoint_arraycopy  = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_jbyte_copy);
    91 address StubRoutines::_arrayof_jshort_disjoint_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_jshort_copy);
    92 address StubRoutines::_arrayof_jint_disjoint_arraycopy   = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_jint_copy);
    93 address StubRoutines::_arrayof_jlong_disjoint_arraycopy  = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_jlong_copy);
    94 address StubRoutines::_arrayof_oop_disjoint_arraycopy  = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_oop_copy);
    96 address StubRoutines::_checkcast_arraycopy               = NULL;
    97 address StubRoutines::_unsafe_arraycopy                  = NULL;
    98 address StubRoutines::_generic_arraycopy                 = NULL;
   101 address StubRoutines::_jbyte_fill;
   102 address StubRoutines::_jshort_fill;
   103 address StubRoutines::_jint_fill;
   104 address StubRoutines::_arrayof_jbyte_fill;
   105 address StubRoutines::_arrayof_jshort_fill;
   106 address StubRoutines::_arrayof_jint_fill;
   109 double (* StubRoutines::_intrinsic_log   )(double) = NULL;
   110 double (* StubRoutines::_intrinsic_log10 )(double) = NULL;
   111 double (* StubRoutines::_intrinsic_exp   )(double) = NULL;
   112 double (* StubRoutines::_intrinsic_pow   )(double, double) = NULL;
   113 double (* StubRoutines::_intrinsic_sin   )(double) = NULL;
   114 double (* StubRoutines::_intrinsic_cos   )(double) = NULL;
   115 double (* StubRoutines::_intrinsic_tan   )(double) = NULL;
   117 // Initialization
   118 //
   119 // Note: to break cycle with universe initialization, stubs are generated in two phases.
   120 // The first one generates stubs needed during universe init (e.g., _handle_must_compile_first_entry).
   121 // The second phase includes all other stubs (which may depend on universe being initialized.)
   123 extern void StubGenerator_generate(CodeBuffer* code, bool all); // only interface to generators
   125 void StubRoutines::initialize1() {
   126   if (_code1 == NULL) {
   127     ResourceMark rm;
   128     TraceTime timer("StubRoutines generation 1", TraceStartupTime);
   129     _code1 = BufferBlob::create("StubRoutines (1)", code_size1);
   130     if (_code1 == NULL) {
   131       vm_exit_out_of_memory(code_size1,
   132                             "CodeCache: no room for StubRoutines (1)");
   133     }
   134     CodeBuffer buffer(_code1->instructions_begin(), _code1->instructions_size());
   135     StubGenerator_generate(&buffer, false);
   136   }
   137 }
   140 #ifdef ASSERT
   141 typedef void (*arraycopy_fn)(address src, address dst, int count);
   143 // simple tests of generated arraycopy functions
   144 static void test_arraycopy_func(address func, int alignment) {
   145   int v = 0xcc;
   146   int v2 = 0x11;
   147   jlong lbuffer[8];
   148   jlong lbuffer2[8];
   149   address fbuffer  = (address) lbuffer;
   150   address fbuffer2 = (address) lbuffer2;
   151   unsigned int i;
   152   for (i = 0; i < sizeof(lbuffer); i++) {
   153     fbuffer[i] = v; fbuffer2[i] = v2;
   154   }
   155   // C++ does not guarantee jlong[] array alignment to 8 bytes.
   156   // Use middle of array to check that memory before it is not modified.
   157   address buffer  = (address) round_to((intptr_t)&lbuffer[4], BytesPerLong);
   158   address buffer2 = (address) round_to((intptr_t)&lbuffer2[4], BytesPerLong);
   159   // do an aligned copy
   160   ((arraycopy_fn)func)(buffer, buffer2, 0);
   161   for (i = 0; i < sizeof(lbuffer); i++) {
   162     assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
   163   }
   164   // adjust destination alignment
   165   ((arraycopy_fn)func)(buffer, buffer2 + alignment, 0);
   166   for (i = 0; i < sizeof(lbuffer); i++) {
   167     assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
   168   }
   169   // adjust source alignment
   170   ((arraycopy_fn)func)(buffer + alignment, buffer2, 0);
   171   for (i = 0; i < sizeof(lbuffer); i++) {
   172     assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
   173   }
   174 }
   175 #endif
   178 void StubRoutines::initialize2() {
   179   if (_code2 == NULL) {
   180     ResourceMark rm;
   181     TraceTime timer("StubRoutines generation 2", TraceStartupTime);
   182     _code2 = BufferBlob::create("StubRoutines (2)", code_size2);
   183     if (_code2 == NULL) {
   184       vm_exit_out_of_memory(code_size2,
   185                             "CodeCache: no room for StubRoutines (2)");
   186     }
   187     CodeBuffer buffer(_code2->instructions_begin(), _code2->instructions_size());
   188     StubGenerator_generate(&buffer, true);
   189   }
   191 #ifdef ASSERT
   193 #define TEST_ARRAYCOPY(type)                                                    \
   194   test_arraycopy_func(          type##_arraycopy(),          sizeof(type));     \
   195   test_arraycopy_func(          type##_disjoint_arraycopy(), sizeof(type));     \
   196   test_arraycopy_func(arrayof_##type##_arraycopy(),          sizeof(HeapWord)); \
   197   test_arraycopy_func(arrayof_##type##_disjoint_arraycopy(), sizeof(HeapWord))
   199   // Make sure all the arraycopy stubs properly handle zero count
   200   TEST_ARRAYCOPY(jbyte);
   201   TEST_ARRAYCOPY(jshort);
   202   TEST_ARRAYCOPY(jint);
   203   TEST_ARRAYCOPY(jlong);
   205 #undef TEST_ARRAYCOPY
   207 #define TEST_FILL(type)                                                                      \
   208   if (_##type##_fill != NULL) {                                                              \
   209     union {                                                                                  \
   210       double d;                                                                              \
   211       type body[96];                                                                         \
   212     } s;                                                                                     \
   213                                                                                              \
   214     int v = 32;                                                                              \
   215     for (int offset = -2; offset <= 2; offset++) {                                           \
   216       for (int i = 0; i < 96; i++) {                                                         \
   217         s.body[i] = 1;                                                                       \
   218       }                                                                                      \
   219       type* start = s.body + 8 + offset;                                                     \
   220       for (int aligned = 0; aligned < 2; aligned++) {                                        \
   221         if (aligned) {                                                                       \
   222           if (((intptr_t)start) % HeapWordSize == 0) {                                       \
   223             ((void (*)(type*, int, int))StubRoutines::_arrayof_##type##_fill)(start, v, 80); \
   224           } else {                                                                           \
   225             continue;                                                                        \
   226           }                                                                                  \
   227         } else {                                                                             \
   228           ((void (*)(type*, int, int))StubRoutines::_##type##_fill)(start, v, 80);           \
   229         }                                                                                    \
   230         for (int i = 0; i < 96; i++) {                                                       \
   231           if (i < (8 + offset) || i >= (88 + offset)) {                                      \
   232             assert(s.body[i] == 1, "what?");                                                 \
   233           } else {                                                                           \
   234             assert(s.body[i] == 32, "what?");                                                \
   235           }                                                                                  \
   236         }                                                                                    \
   237       }                                                                                      \
   238     }                                                                                        \
   239   }                                                                                          \
   241   TEST_FILL(jbyte);
   242   TEST_FILL(jshort);
   243   TEST_FILL(jint);
   245 #undef TEST_FILL
   247 #define TEST_COPYRTN(type) \
   248   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::conjoint_##type##s_atomic),  sizeof(type)); \
   249   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::arrayof_conjoint_##type##s), (int)MAX2(sizeof(HeapWord), sizeof(type)))
   251   // Make sure all the copy runtime routines properly handle zero count
   252   TEST_COPYRTN(jbyte);
   253   TEST_COPYRTN(jshort);
   254   TEST_COPYRTN(jint);
   255   TEST_COPYRTN(jlong);
   257 #undef TEST_COPYRTN
   259   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::conjoint_words), sizeof(HeapWord));
   260   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::disjoint_words), sizeof(HeapWord));
   261   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::disjoint_words_atomic), sizeof(HeapWord));
   262   // Aligned to BytesPerLong
   263   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_conjoint_words), sizeof(jlong));
   264   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_disjoint_words), sizeof(jlong));
   266 #endif
   267 }
   270 void stubRoutines_init1() { StubRoutines::initialize1(); }
   271 void stubRoutines_init2() { StubRoutines::initialize2(); }
   273 //
   274 // Default versions of arraycopy functions
   275 //
   277 static void gen_arraycopy_barrier_pre(oop* dest, size_t count) {
   278     assert(count != 0, "count should be non-zero");
   279     assert(count <= (size_t)max_intx, "count too large");
   280     BarrierSet* bs = Universe::heap()->barrier_set();
   281     assert(bs->has_write_ref_array_pre_opt(), "Must have pre-barrier opt");
   282     bs->write_ref_array_pre(dest, (int)count);
   283 }
   285 static void gen_arraycopy_barrier(oop* dest, size_t count) {
   286     assert(count != 0, "count should be non-zero");
   287     BarrierSet* bs = Universe::heap()->barrier_set();
   288     assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt");
   289     bs->write_ref_array((HeapWord*)dest, count);
   290 }
   292 JRT_LEAF(void, StubRoutines::jbyte_copy(jbyte* src, jbyte* dest, size_t count))
   293 #ifndef PRODUCT
   294   SharedRuntime::_jbyte_array_copy_ctr++;      // Slow-path byte array copy
   295 #endif // !PRODUCT
   296   Copy::conjoint_jbytes_atomic(src, dest, count);
   297 JRT_END
   299 JRT_LEAF(void, StubRoutines::jshort_copy(jshort* src, jshort* dest, size_t count))
   300 #ifndef PRODUCT
   301   SharedRuntime::_jshort_array_copy_ctr++;     // Slow-path short/char array copy
   302 #endif // !PRODUCT
   303   Copy::conjoint_jshorts_atomic(src, dest, count);
   304 JRT_END
   306 JRT_LEAF(void, StubRoutines::jint_copy(jint* src, jint* dest, size_t count))
   307 #ifndef PRODUCT
   308   SharedRuntime::_jint_array_copy_ctr++;       // Slow-path int/float array copy
   309 #endif // !PRODUCT
   310   Copy::conjoint_jints_atomic(src, dest, count);
   311 JRT_END
   313 JRT_LEAF(void, StubRoutines::jlong_copy(jlong* src, jlong* dest, size_t count))
   314 #ifndef PRODUCT
   315   SharedRuntime::_jlong_array_copy_ctr++;      // Slow-path long/double array copy
   316 #endif // !PRODUCT
   317   Copy::conjoint_jlongs_atomic(src, dest, count);
   318 JRT_END
   320 JRT_LEAF(void, StubRoutines::oop_copy(oop* src, oop* dest, size_t count))
   321 #ifndef PRODUCT
   322   SharedRuntime::_oop_array_copy_ctr++;        // Slow-path oop array copy
   323 #endif // !PRODUCT
   324   assert(count != 0, "count should be non-zero");
   325   gen_arraycopy_barrier_pre(dest, count);
   326   Copy::conjoint_oops_atomic(src, dest, count);
   327   gen_arraycopy_barrier(dest, count);
   328 JRT_END
   330 JRT_LEAF(void, StubRoutines::arrayof_jbyte_copy(HeapWord* src, HeapWord* dest, size_t count))
   331 #ifndef PRODUCT
   332   SharedRuntime::_jbyte_array_copy_ctr++;      // Slow-path byte array copy
   333 #endif // !PRODUCT
   334   Copy::arrayof_conjoint_jbytes(src, dest, count);
   335 JRT_END
   337 JRT_LEAF(void, StubRoutines::arrayof_jshort_copy(HeapWord* src, HeapWord* dest, size_t count))
   338 #ifndef PRODUCT
   339   SharedRuntime::_jshort_array_copy_ctr++;     // Slow-path short/char array copy
   340 #endif // !PRODUCT
   341   Copy::arrayof_conjoint_jshorts(src, dest, count);
   342 JRT_END
   344 JRT_LEAF(void, StubRoutines::arrayof_jint_copy(HeapWord* src, HeapWord* dest, size_t count))
   345 #ifndef PRODUCT
   346   SharedRuntime::_jint_array_copy_ctr++;       // Slow-path int/float array copy
   347 #endif // !PRODUCT
   348   Copy::arrayof_conjoint_jints(src, dest, count);
   349 JRT_END
   351 JRT_LEAF(void, StubRoutines::arrayof_jlong_copy(HeapWord* src, HeapWord* dest, size_t count))
   352 #ifndef PRODUCT
   353   SharedRuntime::_jlong_array_copy_ctr++;       // Slow-path int/float array copy
   354 #endif // !PRODUCT
   355   Copy::arrayof_conjoint_jlongs(src, dest, count);
   356 JRT_END
   358 JRT_LEAF(void, StubRoutines::arrayof_oop_copy(HeapWord* src, HeapWord* dest, size_t count))
   359 #ifndef PRODUCT
   360   SharedRuntime::_oop_array_copy_ctr++;        // Slow-path oop array copy
   361 #endif // !PRODUCT
   362   assert(count != 0, "count should be non-zero");
   363   gen_arraycopy_barrier_pre((oop *) dest, count);
   364   Copy::arrayof_conjoint_oops(src, dest, count);
   365   gen_arraycopy_barrier((oop *) dest, count);
   366 JRT_END
   369 address StubRoutines::select_fill_function(BasicType t, bool aligned, const char* &name) {
   370 #define RETURN_STUB(xxx_fill) { \
   371   name = #xxx_fill; \
   372   return StubRoutines::xxx_fill(); }
   374   switch (t) {
   375   case T_BYTE:
   376   case T_BOOLEAN:
   377     if (!aligned) RETURN_STUB(jbyte_fill);
   378     RETURN_STUB(arrayof_jbyte_fill);
   379   case T_CHAR:
   380   case T_SHORT:
   381     if (!aligned) RETURN_STUB(jshort_fill);
   382     RETURN_STUB(arrayof_jshort_fill);
   383   case T_INT:
   384   case T_FLOAT:
   385     if (!aligned) RETURN_STUB(jint_fill);
   386     RETURN_STUB(arrayof_jint_fill);
   387   case T_DOUBLE:
   388   case T_LONG:
   389   case T_ARRAY:
   390   case T_OBJECT:
   391   case T_NARROWOOP:
   392   case T_ADDRESS:
   393     // Currently unsupported
   394     return NULL;
   396   default:
   397     ShouldNotReachHere();
   398     return NULL;
   399   }
   401 #undef RETURN_STUB
   402 }

mercurial