< prev index next >

src/hotspot/share/runtime/stubRoutines.cpp

Print this page
rev 50307 : [mq]: cont


  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  */
  24 
  25 #include "precompiled.hpp"
  26 #include "asm/codeBuffer.hpp"
  27 #include "memory/resourceArea.hpp"
  28 #include "oops/access.inline.hpp"
  29 #include "oops/oop.inline.hpp"

  30 #include "runtime/interfaceSupport.inline.hpp"
  31 #include "runtime/timerTrace.hpp"
  32 #include "runtime/sharedRuntime.hpp"
  33 #include "runtime/stubRoutines.hpp"
  34 #include "utilities/align.hpp"
  35 #include "utilities/copy.hpp"
  36 #include "utilities/vmError.hpp"
  37 #ifdef COMPILER2
  38 #include "opto/runtime.hpp"
  39 #endif
  40 
  41 
  42 // Implementation of StubRoutines - for a description
  43 // of how to extend it, see the header file.
  44 
  45 // Class Variables
  46 
  47 BufferBlob* StubRoutines::_code1                                = NULL;
  48 BufferBlob* StubRoutines::_code2                                = NULL;

  49 
  50 address StubRoutines::_call_stub_return_address                 = NULL;
  51 address StubRoutines::_call_stub_entry                          = NULL;
  52 
  53 address StubRoutines::_catch_exception_entry                    = NULL;
  54 address StubRoutines::_forward_exception_entry                  = NULL;
  55 address StubRoutines::_throw_AbstractMethodError_entry          = NULL;
  56 address StubRoutines::_throw_IncompatibleClassChangeError_entry = NULL;
  57 address StubRoutines::_throw_NullPointerException_at_call_entry = NULL;
  58 address StubRoutines::_throw_StackOverflowError_entry           = NULL;
  59 address StubRoutines::_throw_delayed_StackOverflowError_entry   = NULL;
  60 jint    StubRoutines::_verify_oop_count                         = 0;
  61 address StubRoutines::_verify_oop_subroutine_entry              = NULL;
  62 address StubRoutines::_atomic_xchg_entry                        = NULL;
  63 address StubRoutines::_atomic_xchg_long_entry                   = NULL;
  64 address StubRoutines::_atomic_store_entry                       = NULL;
  65 address StubRoutines::_atomic_cmpxchg_entry                     = NULL;
  66 address StubRoutines::_atomic_cmpxchg_byte_entry                = NULL;
  67 address StubRoutines::_atomic_cmpxchg_long_entry                = NULL;
  68 address StubRoutines::_atomic_add_entry                         = NULL;


 157 address StubRoutines::_dpow = NULL;
 158 address StubRoutines::_dsin = NULL;
 159 address StubRoutines::_dcos = NULL;
 160 address StubRoutines::_dlibm_sin_cos_huge = NULL;
 161 address StubRoutines::_dlibm_reduce_pi04l = NULL;
 162 address StubRoutines::_dlibm_tan_cot_huge = NULL;
 163 address StubRoutines::_dtan = NULL;
 164 
 165 double (* StubRoutines::_intrinsic_log10 )(double) = NULL;
 166 double (* StubRoutines::_intrinsic_sin   )(double) = NULL;
 167 double (* StubRoutines::_intrinsic_cos   )(double) = NULL;
 168 double (* StubRoutines::_intrinsic_tan   )(double) = NULL;
 169 
 170 address StubRoutines::_safefetch32_entry                 = NULL;
 171 address StubRoutines::_safefetch32_fault_pc              = NULL;
 172 address StubRoutines::_safefetch32_continuation_pc       = NULL;
 173 address StubRoutines::_safefetchN_entry                  = NULL;
 174 address StubRoutines::_safefetchN_fault_pc               = NULL;
 175 address StubRoutines::_safefetchN_continuation_pc        = NULL;
 176 






 177 // Initialization
 178 //
 179 // Note: to break cycle with universe initialization, stubs are generated in two phases.
 180 // The first one generates stubs needed during universe init (e.g., _handle_must_compile_first_entry).
 181 // The second phase includes all other stubs (which may depend on universe being initialized.)
 182 
 183 extern void StubGenerator_generate(CodeBuffer* code, bool all); // only interface to generators
 184 
 185 void StubRoutines::initialize1() {
 186   if (_code1 == NULL) {
 187     ResourceMark rm;
 188     TraceTime timer("StubRoutines generation 1", TRACETIME_LOG(Info, startuptime));
 189     _code1 = BufferBlob::create("StubRoutines (1)", code_size1);
 190     if (_code1 == NULL) {
 191       vm_exit_out_of_memory(code_size1, OOM_MALLOC_ERROR, "CodeCache: no room for StubRoutines (1)");
 192     }
 193     CodeBuffer buffer(_code1);
 194     StubGenerator_generate(&buffer, false);
 195     // When new stubs added we need to make sure there is some space left
 196     // to catch situation when we should increase size again.
 197     assert(code_size1 == 0 || buffer.insts_remaining() > 200, "increase code_size1");
 198   }
 199 }
 200 
 201 
 202 #ifdef ASSERT
 203 typedef void (*arraycopy_fn)(address src, address dst, int count);
 204 
 205 // simple tests of generated arraycopy functions
 206 static void test_arraycopy_func(address func, int alignment) {
 207   int v = 0xcc;
 208   int v2 = 0x11;
 209   jlong lbuffer[8];
 210   jlong lbuffer2[8];
 211   address fbuffer  = (address) lbuffer;
 212   address fbuffer2 = (address) lbuffer2;
 213   unsigned int i;
 214   for (i = 0; i < sizeof(lbuffer); i++) {
 215     fbuffer[i] = v; fbuffer2[i] = v2;
 216   }
 217   // C++ does not guarantee jlong[] array alignment to 8 bytes.
 218   // Use middle of array to check that memory before it is not modified.
 219   address buffer  = align_up((address)&lbuffer[4], BytesPerLong);
 220   address buffer2 = align_up((address)&lbuffer2[4], BytesPerLong);
 221   // do an aligned copy


 252 static void test_safefetchN() {
 253   if (CanUseSafeFetchN()) {
 254 #ifdef _LP64
 255     const intptr_t v1 = UCONST64(0xABCD00000000ABCD);
 256     const intptr_t v2 = UCONST64(0xDEFD00000000DEFD);
 257 #else
 258     const intptr_t v1 = 0xABCDABCD;
 259     const intptr_t v2 = 0xDEFDDEFD;
 260 #endif
 261     intptr_t dummy = v1;
 262     intptr_t* const p_invalid = (intptr_t*) VMError::get_segfault_address();
 263     intptr_t* const p_valid = &dummy;
 264     intptr_t result_invalid = SafeFetchN(p_invalid, v2);
 265     assert(result_invalid == v2, "SafeFetchN error");
 266     intptr_t result_valid = SafeFetchN(p_valid, v2);
 267     assert(result_valid == v1, "SafeFetchN error");
 268   }
 269 }
 270 #endif
 271 
















 272 void StubRoutines::initialize2() {
 273   if (_code2 == NULL) {
 274     ResourceMark rm;
 275     TraceTime timer("StubRoutines generation 2", TRACETIME_LOG(Info, startuptime));
 276     _code2 = BufferBlob::create("StubRoutines (2)", code_size2);
 277     if (_code2 == NULL) {
 278       vm_exit_out_of_memory(code_size2, OOM_MALLOC_ERROR, "CodeCache: no room for StubRoutines (2)");
 279     }
 280     CodeBuffer buffer(_code2);
 281     StubGenerator_generate(&buffer, true);
 282     // When new stubs added we need to make sure there is some space left
 283     // to catch situation when we should increase size again.
 284     assert(code_size2 == 0 || buffer.insts_remaining() > 200, "increase code_size2");
 285   }
 286 
 287 #ifdef ASSERT
 288 
 289 #define TEST_ARRAYCOPY(type)                                                    \
 290   test_arraycopy_func(          type##_arraycopy(),          sizeof(type));     \
 291   test_arraycopy_func(          type##_disjoint_arraycopy(), sizeof(type));     \
 292   test_arraycopy_func(arrayof_##type##_arraycopy(),          sizeof(HeapWord)); \
 293   test_arraycopy_func(arrayof_##type##_disjoint_arraycopy(), sizeof(HeapWord))
 294 
 295   // Make sure all the arraycopy stubs properly handle zero count
 296   TEST_ARRAYCOPY(jbyte);
 297   TEST_ARRAYCOPY(jshort);
 298   TEST_ARRAYCOPY(jint);
 299   TEST_ARRAYCOPY(jlong);
 300 
 301 #undef TEST_ARRAYCOPY


 355   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::conjoint_words), sizeof(HeapWord));
 356   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::disjoint_words), sizeof(HeapWord));
 357   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::disjoint_words_atomic), sizeof(HeapWord));
 358   // Aligned to BytesPerLong
 359   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_conjoint_words), sizeof(jlong));
 360   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_disjoint_words), sizeof(jlong));
 361 
 362   // test safefetch routines
 363   // Not on Windows 32bit until 8074860 is fixed
 364 #if ! (defined(_WIN32) && defined(_M_IX86))
 365   test_safefetch32();
 366   test_safefetchN();
 367 #endif
 368 
 369 #endif
 370 }
 371 
 372 
 373 void stubRoutines_init1() { StubRoutines::initialize1(); }
 374 void stubRoutines_init2() { StubRoutines::initialize2(); }

 375 
 376 //
 377 // Default versions of arraycopy functions
 378 //
 379 
 380 JRT_LEAF(void, StubRoutines::jbyte_copy(jbyte* src, jbyte* dest, size_t count))
 381 #ifndef PRODUCT
 382   SharedRuntime::_jbyte_array_copy_ctr++;      // Slow-path byte array copy
 383 #endif // !PRODUCT
 384   Copy::conjoint_jbytes_atomic(src, dest, count);
 385 JRT_END
 386 
 387 JRT_LEAF(void, StubRoutines::jshort_copy(jshort* src, jshort* dest, size_t count))
 388 #ifndef PRODUCT
 389   SharedRuntime::_jshort_array_copy_ctr++;     // Slow-path short/char array copy
 390 #endif // !PRODUCT
 391   Copy::conjoint_jshorts_atomic(src, dest, count);
 392 JRT_END
 393 
 394 JRT_LEAF(void, StubRoutines::jint_copy(jint* src, jint* dest, size_t count))




  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  */
  24 
  25 #include "precompiled.hpp"
  26 #include "asm/codeBuffer.hpp"
  27 #include "memory/resourceArea.hpp"
  28 #include "oops/access.inline.hpp"
  29 #include "oops/oop.inline.hpp"
  30 #include "runtime/continuation.hpp"
  31 #include "runtime/interfaceSupport.inline.hpp"
  32 #include "runtime/timerTrace.hpp"
  33 #include "runtime/sharedRuntime.hpp"
  34 #include "runtime/stubRoutines.hpp"
  35 #include "utilities/align.hpp"
  36 #include "utilities/copy.hpp"
  37 #include "utilities/vmError.hpp"
  38 #ifdef COMPILER2
  39 #include "opto/runtime.hpp"
  40 #endif
  41 
  42 
  43 // Implementation of StubRoutines - for a description
  44 // of how to extend it, see the header file.
  45 
  46 // Class Variables
  47 
  48 BufferBlob* StubRoutines::_code1                                = NULL;
  49 BufferBlob* StubRoutines::_code2                                = NULL;
  50 BufferBlob* StubRoutines::_code3                                = NULL;
  51 
  52 address StubRoutines::_call_stub_return_address                 = NULL;
  53 address StubRoutines::_call_stub_entry                          = NULL;
  54 
  55 address StubRoutines::_catch_exception_entry                    = NULL;
  56 address StubRoutines::_forward_exception_entry                  = NULL;
  57 address StubRoutines::_throw_AbstractMethodError_entry          = NULL;
  58 address StubRoutines::_throw_IncompatibleClassChangeError_entry = NULL;
  59 address StubRoutines::_throw_NullPointerException_at_call_entry = NULL;
  60 address StubRoutines::_throw_StackOverflowError_entry           = NULL;
  61 address StubRoutines::_throw_delayed_StackOverflowError_entry   = NULL;
  62 jint    StubRoutines::_verify_oop_count                         = 0;
  63 address StubRoutines::_verify_oop_subroutine_entry              = NULL;
  64 address StubRoutines::_atomic_xchg_entry                        = NULL;
  65 address StubRoutines::_atomic_xchg_long_entry                   = NULL;
  66 address StubRoutines::_atomic_store_entry                       = NULL;
  67 address StubRoutines::_atomic_cmpxchg_entry                     = NULL;
  68 address StubRoutines::_atomic_cmpxchg_byte_entry                = NULL;
  69 address StubRoutines::_atomic_cmpxchg_long_entry                = NULL;
  70 address StubRoutines::_atomic_add_entry                         = NULL;


 159 address StubRoutines::_dpow = NULL;
 160 address StubRoutines::_dsin = NULL;
 161 address StubRoutines::_dcos = NULL;
 162 address StubRoutines::_dlibm_sin_cos_huge = NULL;
 163 address StubRoutines::_dlibm_reduce_pi04l = NULL;
 164 address StubRoutines::_dlibm_tan_cot_huge = NULL;
 165 address StubRoutines::_dtan = NULL;
 166 
 167 double (* StubRoutines::_intrinsic_log10 )(double) = NULL;
 168 double (* StubRoutines::_intrinsic_sin   )(double) = NULL;
 169 double (* StubRoutines::_intrinsic_cos   )(double) = NULL;
 170 double (* StubRoutines::_intrinsic_tan   )(double) = NULL;
 171 
 172 address StubRoutines::_safefetch32_entry                 = NULL;
 173 address StubRoutines::_safefetch32_fault_pc              = NULL;
 174 address StubRoutines::_safefetch32_continuation_pc       = NULL;
 175 address StubRoutines::_safefetchN_entry                  = NULL;
 176 address StubRoutines::_safefetchN_fault_pc               = NULL;
 177 address StubRoutines::_safefetchN_continuation_pc        = NULL;
 178 
 179 address StubRoutines::_cont_doYield       = NULL;
 180 address StubRoutines::_cont_thaw          = NULL;
 181 address StubRoutines::_cont_returnBarrier = NULL;
 182 address StubRoutines::_cont_getSP         = NULL;
 183 address StubRoutines::_cont_getPC         = NULL;
 184 
 185 // Initialization
 186 //
 187 // Note: to break cycle with universe initialization, stubs are generated in two phases.
 188 // The first one generates stubs needed during universe init (e.g., _handle_must_compile_first_entry).
 189 // The second phase includes all other stubs (which may depend on universe being initialized.)
 190 
 191 extern void StubGenerator_generate(CodeBuffer* code, int phase); // only interface to generators
 192 
 193 void StubRoutines::initialize1() {
 194   if (_code1 == NULL) {
 195     ResourceMark rm;
 196     TraceTime timer("StubRoutines generation 1", TRACETIME_LOG(Info, startuptime));
 197     _code1 = BufferBlob::create("StubRoutines (1)", code_size1);
 198     if (_code1 == NULL) {
 199       vm_exit_out_of_memory(code_size1, OOM_MALLOC_ERROR, "CodeCache: no room for StubRoutines (1)");
 200     }
 201     CodeBuffer buffer(_code1);
 202     StubGenerator_generate(&buffer, 0);
 203     // When new stubs added we need to make sure there is some space left
 204     // to catch situation when we should increase size again.
 205     assert(code_size1 == 0 || buffer.insts_remaining() > 200, "increase code_size1");
 206   }
 207 }
 208 

 209 #ifdef ASSERT
 210 typedef void (*arraycopy_fn)(address src, address dst, int count);
 211 
 212 // simple tests of generated arraycopy functions
 213 static void test_arraycopy_func(address func, int alignment) {
 214   int v = 0xcc;
 215   int v2 = 0x11;
 216   jlong lbuffer[8];
 217   jlong lbuffer2[8];
 218   address fbuffer  = (address) lbuffer;
 219   address fbuffer2 = (address) lbuffer2;
 220   unsigned int i;
 221   for (i = 0; i < sizeof(lbuffer); i++) {
 222     fbuffer[i] = v; fbuffer2[i] = v2;
 223   }
 224   // C++ does not guarantee jlong[] array alignment to 8 bytes.
 225   // Use middle of array to check that memory before it is not modified.
 226   address buffer  = align_up((address)&lbuffer[4], BytesPerLong);
 227   address buffer2 = align_up((address)&lbuffer2[4], BytesPerLong);
 228   // do an aligned copy


 259 static void test_safefetchN() {
 260   if (CanUseSafeFetchN()) {
 261 #ifdef _LP64
 262     const intptr_t v1 = UCONST64(0xABCD00000000ABCD);
 263     const intptr_t v2 = UCONST64(0xDEFD00000000DEFD);
 264 #else
 265     const intptr_t v1 = 0xABCDABCD;
 266     const intptr_t v2 = 0xDEFDDEFD;
 267 #endif
 268     intptr_t dummy = v1;
 269     intptr_t* const p_invalid = (intptr_t*) VMError::get_segfault_address();
 270     intptr_t* const p_valid = &dummy;
 271     intptr_t result_invalid = SafeFetchN(p_invalid, v2);
 272     assert(result_invalid == v2, "SafeFetchN error");
 273     intptr_t result_valid = SafeFetchN(p_valid, v2);
 274     assert(result_valid == v1, "SafeFetchN error");
 275   }
 276 }
 277 #endif
 278 
 279 void StubRoutines::initializeContinuationStubs() {
 280   if (_code3 == NULL) {
 281     ResourceMark rm;
 282     TraceTime timer("StubRoutines generation 3", TRACETIME_LOG(Info, startuptime));
 283     _code3 = BufferBlob::create("StubRoutines (3)", code_size2);
 284     if (_code3 == NULL) {
 285       vm_exit_out_of_memory(code_size2, OOM_MALLOC_ERROR, "CodeCache: no room for StubRoutines (3)");
 286     }
 287     CodeBuffer buffer(_code3);
 288     StubGenerator_generate(&buffer, 1);
 289     // When new stubs added we need to make sure there is some space left
 290     // to catch situation when we should increase size again.
 291     assert(code_size2 == 0 || buffer.insts_remaining() > 200, "increase code_size3");
 292   }
 293 }
 294 
 295 void StubRoutines::initialize2() {
 296   if (_code2 == NULL) {
 297     ResourceMark rm;
 298     TraceTime timer("StubRoutines generation 2", TRACETIME_LOG(Info, startuptime));
 299     _code2 = BufferBlob::create("StubRoutines (2)", code_size2);
 300     if (_code2 == NULL) {
 301       vm_exit_out_of_memory(code_size2, OOM_MALLOC_ERROR, "CodeCache: no room for StubRoutines (2)");
 302     }
 303     CodeBuffer buffer(_code2);
 304     StubGenerator_generate(&buffer, 2);
 305     // When new stubs added we need to make sure there is some space left
 306     // to catch situation when we should increase size again.
 307     assert(code_size2 == 0 || buffer.insts_remaining() > 200, "increase code_size2");
 308   }
 309 
 310 #ifdef ASSERT
 311 
 312 #define TEST_ARRAYCOPY(type)                                                    \
 313   test_arraycopy_func(          type##_arraycopy(),          sizeof(type));     \
 314   test_arraycopy_func(          type##_disjoint_arraycopy(), sizeof(type));     \
 315   test_arraycopy_func(arrayof_##type##_arraycopy(),          sizeof(HeapWord)); \
 316   test_arraycopy_func(arrayof_##type##_disjoint_arraycopy(), sizeof(HeapWord))
 317 
 318   // Make sure all the arraycopy stubs properly handle zero count
 319   TEST_ARRAYCOPY(jbyte);
 320   TEST_ARRAYCOPY(jshort);
 321   TEST_ARRAYCOPY(jint);
 322   TEST_ARRAYCOPY(jlong);
 323 
 324 #undef TEST_ARRAYCOPY


 378   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::conjoint_words), sizeof(HeapWord));
 379   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::disjoint_words), sizeof(HeapWord));
 380   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::disjoint_words_atomic), sizeof(HeapWord));
 381   // Aligned to BytesPerLong
 382   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_conjoint_words), sizeof(jlong));
 383   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_disjoint_words), sizeof(jlong));
 384 
 385   // test safefetch routines
 386   // Not on Windows 32bit until 8074860 is fixed
 387 #if ! (defined(_WIN32) && defined(_M_IX86))
 388   test_safefetch32();
 389   test_safefetchN();
 390 #endif
 391 
 392 #endif
 393 }
 394 
 395 
 396 void stubRoutines_init1() { StubRoutines::initialize1(); }
 397 void stubRoutines_init2() { StubRoutines::initialize2(); }
 398 void stubRoutines_initContinuationStubs() { StubRoutines::initializeContinuationStubs(); }
 399 
 400 //
 401 // Default versions of arraycopy functions
 402 //
 403 
 404 JRT_LEAF(void, StubRoutines::jbyte_copy(jbyte* src, jbyte* dest, size_t count))
 405 #ifndef PRODUCT
 406   SharedRuntime::_jbyte_array_copy_ctr++;      // Slow-path byte array copy
 407 #endif // !PRODUCT
 408   Copy::conjoint_jbytes_atomic(src, dest, count);
 409 JRT_END
 410 
 411 JRT_LEAF(void, StubRoutines::jshort_copy(jshort* src, jshort* dest, size_t count))
 412 #ifndef PRODUCT
 413   SharedRuntime::_jshort_array_copy_ctr++;     // Slow-path short/char array copy
 414 #endif // !PRODUCT
 415   Copy::conjoint_jshorts_atomic(src, dest, count);
 416 JRT_END
 417 
 418 JRT_LEAF(void, StubRoutines::jint_copy(jint* src, jint* dest, size_t count))


< prev index next >