1 /*
   2  * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
   4  * Copyright (c) 2015, Linaro Ltd. All rights reserved.
   5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6  *
   7  * This code is free software; you can redistribute it and/or modify it
   8  * under the terms of the GNU General Public License version 2 only, as
   9  * published by the Free Software Foundation.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  *
  25  */
  26 
  27 // No precompiled headers
  28 #include "asm/macroAssembler.hpp"
  29 #include "classfile/classLoader.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "classfile/vmSymbols.hpp"
  32 #include "code/icBuffer.hpp"
  33 #include "code/vtableStubs.hpp"
  34 #include "interpreter/interpreter.hpp"
  35 #include "jvm_linux.h"
  36 #include "memory/allocation.inline.hpp"
  37 #include "mutex_linux.inline.hpp"
  38 #include "nativeInst_aarch32.hpp"
  39 #include "os_share_linux.hpp"
  40 #include "prims/jniFastGetField.hpp"
  41 #include "prims/jvm.h"
  42 #include "prims/jvm_misc.hpp"
  43 #include "runtime/arguments.hpp"
  44 #include "runtime/extendedPC.hpp"
  45 #include "runtime/frame.inline.hpp"
  46 #include "runtime/interfaceSupport.hpp"
  47 #include "runtime/java.hpp"
  48 #include "runtime/javaCalls.hpp"
  49 #include "runtime/mutexLocker.hpp"
  50 #include "runtime/osThread.hpp"
  51 #include "runtime/sharedRuntime.hpp"
  52 #include "runtime/stubRoutines.hpp"
  53 #include "runtime/thread.inline.hpp"
  54 #include "runtime/timer.hpp"
  55 #include "utilities/events.hpp"
  56 #include "utilities/vmError.hpp"
  57 
  58 // put OS-includes here
  59 # include <sys/types.h>
  60 # include <sys/mman.h>
  61 # include <pthread.h>
  62 # include <signal.h>
  63 # include <errno.h>
  64 # include <dlfcn.h>
  65 # include <stdlib.h>
  66 # include <stdio.h>
  67 # include <unistd.h>
  68 # include <sys/resource.h>
  69 # include <pthread.h>
  70 # include <sys/stat.h>
  71 # include <sys/time.h>
  72 # include <sys/utsname.h>
  73 # include <sys/socket.h>
  74 # include <sys/wait.h>
  75 # include <pwd.h>
  76 # include <poll.h>
  77 # include <ucontext.h>
  78 # include <fpu_control.h>
  79 
  80 #define REG_FP 29
  81 #define SPELL_REG_SP "sp"
  82 #define SPELL_REG_FP "fp"
  83 
  84 extern "C" {
  85   void *linux_aarch32_current_frame_pointer();
  86 }
  87 
  88 address os::current_stack_pointer() {
  89   return (address) linux_aarch32_current_frame_pointer();
  90 }
  91 
  92 char* os::non_memory_address_word() {
  93   // Must never look like an address returned by reserve_memory,
  94   // even in its subfields (as defined by the CPU immediate fields,
  95   // if the CPU splits constants across multiple instructions).
  96 
  97   return (char*) 0xfffffffful;
  98 }
  99 
 100 void os::initialize_thread(Thread *thr) {
 101 }
 102 
 103 address os::Linux::ucontext_get_pc(ucontext_t * uc) {
 104   //FIXME
 105   //return (address)uc->uc_mcontext.pc;
 106   return (address)uc->uc_mcontext.arm_pc;
 107   //FIXME END
 108 }
 109 
 110 void os::Linux::ucontext_set_pc(ucontext_t * uc, address pc) {
 111   //FIXME
 112   //uc->uc_mcontext.pc = (intptr_t)pc;
 113   uc->uc_mcontext.arm_pc = (intptr_t)pc;
 114   //FIXME END
 115 }
 116 
 117 intptr_t* os::Linux::ucontext_get_sp(ucontext_t * uc) {
 118   //FIXME
 119   //return (intptr_t*)uc->uc_mcontext.sp;
 120   return (intptr_t*)uc->uc_mcontext.arm_sp;
 121   //FIXME END
 122 }
 123 
 124 intptr_t* os::Linux::ucontext_get_fp(ucontext_t * uc) {
 125   //FIXME
 126   //return (intptr_t*)uc->uc_mcontext.regs[REG_FP];
 127   return (intptr_t*)uc->uc_mcontext.arm_fp;
 128   //FIXME END
 129 }
 130 
 131 // For Forte Analyzer AsyncGetCallTrace profiling support - thread
 132 // is currently interrupted by SIGPROF.
 133 // os::Solaris::fetch_frame_from_ucontext() tries to skip nested signal
 134 // frames. Currently we don't do that on Linux, so it's the same as
 135 // os::fetch_frame_from_context().
 136 ExtendedPC os::Linux::fetch_frame_from_ucontext(Thread* thread,
 137   ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) {
 138 
 139   assert(thread != NULL, "just checking");
 140   assert(ret_sp != NULL, "just checking");
 141   assert(ret_fp != NULL, "just checking");
 142 
 143   return os::fetch_frame_from_context(uc, ret_sp, ret_fp);
 144 }
 145 
 146 ExtendedPC os::fetch_frame_from_context(void* ucVoid,
 147                     intptr_t** ret_sp, intptr_t** ret_fp) {
 148 
 149   ExtendedPC  epc;
 150   ucontext_t* uc = (ucontext_t*)ucVoid;
 151 
 152   if (uc != NULL) {
 153     epc = ExtendedPC(os::Linux::ucontext_get_pc(uc));
 154     if (ret_sp) *ret_sp = os::Linux::ucontext_get_sp(uc);
 155     if (ret_fp) *ret_fp = os::Linux::ucontext_get_fp(uc);
 156   } else {
 157     // construct empty ExtendedPC for return value checking
 158     epc = ExtendedPC(NULL);
 159     if (ret_sp) *ret_sp = (intptr_t *)NULL;
 160     if (ret_fp) *ret_fp = (intptr_t *)NULL;
 161   }
 162 
 163   return epc;
 164 }
 165 
 166 frame os::fetch_frame_from_context(void* ucVoid) {
 167   intptr_t* sp;
 168   intptr_t* fp;
 169   ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
 170   return frame(sp, fp, epc.pc());
 171 }
 172 
 173 // By default, gcc always saves frame pointer rfp on this stack. This
 174 // may get turned off by -fomit-frame-pointer.
 175 frame os::get_sender_for_C_frame(frame* fr) {
 176   return frame(fr->link(), fr->link(), fr->sender_pc());
 177 }
 178 
 179 intptr_t* _get_previous_fp() {
 180   register intptr_t **fp  __asm__ (SPELL_REG_FP);
 181   return *fp;   // we want what it points to.
 182 }
 183 
 184 
 185 frame os::current_frame() {
 186   intptr_t* fp = _get_previous_fp();
 187   frame myframe((intptr_t*)os::current_stack_pointer(),
 188                 (intptr_t*)fp,
 189                 CAST_FROM_FN_PTR(address, os::current_frame));
 190   if (os::is_first_C_frame(&myframe)) {
 191     // stack is not walkable
 192     return frame();
 193   } else {
 194     return os::get_sender_for_C_frame(&myframe);
 195   }
 196 }
 197 
 198 // Utility functions
 199 
 200 // From IA32 System Programming Guide
 201 enum {
 202   trap_page_fault = 0xE
 203 };
 204 
 205 // An operation in Unsafe has faulted.  We're going to return to the
 206 // instruction after the faulting load or store.  We also set
 207 // pending_unsafe_access_error so that at some point in the future our
 208 // user will get a helpful message.
 209 static address handle_unsafe_access(JavaThread* thread, address pc) {
 210   // pc is the instruction which we must emulate
 211   // doing a no-op is fine:  return garbage from the load
 212   // therefore, compute npc
 213   address npc = pc + NativeInstruction::arm_insn_sz;
 214 
 215   // request an async exception
 216   thread->set_pending_unsafe_access_error();
 217 
 218   // return address of next instruction to execute
 219   return npc;
 220 }
 221 
 222 extern "C" JNIEXPORT int
 223 JVM_handle_linux_signal(int sig,
 224                         siginfo_t* info,
 225                         void* ucVoid,
 226                         int abort_if_unrecognized) {
 227   ucontext_t* uc = (ucontext_t*) ucVoid;
 228 
 229   Thread* t = ThreadLocalStorage::get_thread_slow();
 230 
 231   // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away
 232   // (no destructors can be run)
 233   os::WatcherThreadCrashProtection::check_crash_protection(sig, t);
 234 
 235   SignalHandlerMark shm(t);
 236 
 237   // Note: it's not uncommon that JNI code uses signal/sigset to install
 238   // then restore certain signal handler (e.g. to temporarily block SIGPIPE,
 239   // or have a SIGILL handler when detecting CPU type). When that happens,
 240   // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To
 241   // avoid unnecessary crash when libjsig is not preloaded, try handle signals
 242   // that do not require siginfo/ucontext first.
 243 
 244   if (sig == SIGPIPE || sig == SIGXFSZ) {
 245     // allow chained handler to go first
 246     if (os::Linux::chained_handler(sig, info, ucVoid)) {
 247       return true;
 248     } else {
 249       if (PrintMiscellaneous && (WizardMode || Verbose)) {
 250         char buf[64];
 251         warning("Ignoring %s - see bugs 4229104 or 646499219",
 252                 os::exception_name(sig, buf, sizeof(buf)));
 253       }
 254       return true;
 255     }
 256   }
 257 
 258   JavaThread* thread = NULL;
 259   VMThread* vmthread = NULL;
 260   if (os::Linux::signal_handlers_are_installed) {
 261     if (t != NULL ){
 262       if(t->is_Java_thread()) {
 263         thread = (JavaThread*)t;
 264       }
 265       else if(t->is_VM_thread()){
 266         vmthread = (VMThread *)t;
 267       }
 268     }
 269   }
 270 /*
 271   NOTE: does not seem to work on linux.
 272   if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) {
 273     // can't decode this kind of signal
 274     info = NULL;
 275   } else {
 276     assert(sig == info->si_signo, "bad siginfo");
 277   }
 278 */
 279   // decide if this trap can be handled by a stub
 280   address stub = NULL;
 281 
 282   address pc          = NULL;
 283 
 284   //%note os_trap_1
 285   if (info != NULL && uc != NULL && thread != NULL) {
 286     pc = (address) os::Linux::ucontext_get_pc(uc);
 287 
 288     if (StubRoutines::is_safefetch_fault(pc)) {
 289       os::Linux::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
 290       return 1;
 291     }
 292 
 293     // Handle ALL stack overflow variations here
 294     if (sig == SIGSEGV) {
 295       address addr = (address) info->si_addr;
 296 
 297       // check if fault address is within thread stack
 298       if (addr < thread->stack_base() &&
 299           addr >= thread->stack_base() - thread->stack_size()) {
 300         // stack overflow
 301         if (thread->in_stack_yellow_zone(addr)) {
 302           thread->disable_stack_yellow_zone();
 303           if (thread->thread_state() == _thread_in_Java) {
 304             // Throw a stack overflow exception.  Guard pages will be reenabled
 305             // while unwinding the stack.
 306             stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
 307           } else {
 308             // Thread was in the vm or native code.  Return and try to finish.
 309             return 1;
 310           }
 311         } else if (thread->in_stack_red_zone(addr)) {
 312           // Fatal red zone violation.  Disable the guard pages and fall through
 313           // to handle_unexpected_exception way down below.
 314           thread->disable_stack_red_zone();
 315           tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
 316 
 317           // This is a likely cause, but hard to verify. Let's just print
 318           // it as a hint.
 319           tty->print_raw_cr("Please check if any of your loaded .so files has "
 320                             "enabled executable stack (see man page execstack(8))");
 321         } else {
 322           // Accessing stack address below sp may cause SEGV if current
 323           // thread has MAP_GROWSDOWN stack. This should only happen when
 324           // current thread was created by user code with MAP_GROWSDOWN flag
 325           // and then attached to VM. See notes in os_linux.cpp.
 326           if (thread->osthread()->expanding_stack() == 0) {
 327              thread->osthread()->set_expanding_stack();
 328              if (os::Linux::manually_expand_stack(thread, addr)) {
 329                thread->osthread()->clear_expanding_stack();
 330                return 1;
 331              }
 332              thread->osthread()->clear_expanding_stack();
 333           } else {
 334              fatal("recursive segv. expanding stack.");
 335           }
 336         }
 337       }
 338     }
 339 
 340     if (thread->thread_state() == _thread_in_Java) {
 341       // Java thread running in Java code => find exception handler if any
 342       // a fault inside compiled code, the interpreter, or a stub
 343 
 344       // Handle signal from NativeJump::patch_verified_entry().
 345       if ((sig == SIGILL || sig == SIGTRAP)
 346           && nativeInstruction_at(pc)->is_sigill_zombie_not_entrant()) {
 347         if (TraceTraps) {
 348           tty->print_cr("trap: zombie_not_entrant (%s)", (sig == SIGTRAP) ? "SIGTRAP" : "SIGILL");
 349         }
 350         stub = SharedRuntime::get_handle_wrong_method_stub();
 351       } else if (sig == SIGSEGV && os::is_poll_address((address)info->si_addr)) {
 352         stub = SharedRuntime::get_poll_stub(pc);
 353       } else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) {
 354         // BugId 4454115: A read from a MappedByteBuffer can fault
 355         // here if the underlying file has been truncated.
 356         // Do not crash the VM in such a case.
 357         CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
 358         nmethod* nm = (cb != NULL && cb->is_nmethod()) ? (nmethod*)cb : NULL;
 359         if (nm != NULL && nm->has_unsafe_access()) {
 360           stub = handle_unsafe_access(thread, pc);
 361         }
 362       }
 363       else
 364 
 365       if (sig == SIGFPE  &&
 366           (info->si_code == FPE_INTDIV || info->si_code == FPE_FLTDIV)) {
 367         stub =
 368           SharedRuntime::
 369           continuation_for_implicit_exception(thread,
 370                                               pc,
 371                                               SharedRuntime::
 372                                               IMPLICIT_DIVIDE_BY_ZERO);
 373       } else if (sig == SIGSEGV &&
 374                !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) {
 375           // Determination of interpreter/vtable stub/compiled code null exception
 376           stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
 377       }
 378     } else if (sig == SIGILL && VM_Version::is_determine_features_test_running()) {
 379         // SIGILL must be caused by VM_Version::get_processor_features().
 380         *(int *)pc = Assembler::nop_insn; // patch instruction to NOP to indicate that it causes a SIGILL,
 381                         // flushing of icache is not necessary.
 382         stub = pc + 4;  // continue with next instruction.
 383     } else if (thread->thread_state() == _thread_in_vm &&
 384                sig == SIGBUS && /* info->si_code == BUS_OBJERR && */
 385                thread->doing_unsafe_access()) {
 386         stub = handle_unsafe_access(thread, pc);
 387     }
 388 
 389     // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
 390     // and the heap gets shrunk before the field access.
 391     if ((sig == SIGSEGV) || (sig == SIGBUS)) {
 392       address addr = JNI_FastGetField::find_slowcase_pc(pc);
 393       if (addr != (address)-1) {
 394         stub = addr;
 395       }
 396     }
 397 
 398     // Check to see if we caught the safepoint code in the
 399     // process of write protecting the memory serialization page.
 400     // It write enables the page immediately after protecting it
 401     // so we can just return to retry the write.
 402     if ((sig == SIGSEGV) &&
 403         os::is_memory_serialize_page(thread, (address) info->si_addr)) {
 404       // Block current thread until the memory serialize page permission restored.
 405       os::block_on_serialize_page_trap();
 406       return true;
 407     }
 408   }
 409 
 410   if (stub != NULL) {
 411     // save all thread context in case we need to restore it
 412     if (thread != NULL) thread->set_saved_exception_pc(pc);
 413 
 414     os::Linux::ucontext_set_pc(uc, stub);
 415     return true;
 416   }
 417 
 418   // signal-chaining
 419   if (os::Linux::chained_handler(sig, info, ucVoid)) {
 420      return true;
 421   }
 422 
 423   if (!abort_if_unrecognized) {
 424     // caller wants another chance, so give it to him
 425     return false;
 426   }
 427 
 428   if (pc == NULL && uc != NULL) {
 429     pc = os::Linux::ucontext_get_pc(uc);
 430   }
 431 
 432   // unmask current signal
 433   sigset_t newset;
 434   sigemptyset(&newset);
 435   sigaddset(&newset, sig);
 436   sigprocmask(SIG_UNBLOCK, &newset, NULL);
 437 
 438   VMError err(t, sig, pc, info, ucVoid);
 439   err.report_and_die();
 440 
 441   ShouldNotReachHere();
 442   return true; // Mute compiler
 443 }
 444 
 445 void os::Linux::init_thread_fpu_state(void) {
 446 }
 447 
 448 int os::Linux::get_fpu_control_word(void) {
 449   return 0;
 450 }
 451 
 452 void os::Linux::set_fpu_control_word(int fpu_control) {
 453 }
 454 
 455 // Check that the linux kernel version is 2.4 or higher since earlier
 456 // versions do not support SSE without patches.
 457 bool os::supports_sse() {
 458   return true;
 459 }
 460 
 461 bool os::is_allocatable(size_t bytes) {
 462   return true;
 463 }
 464 
 465 ////////////////////////////////////////////////////////////////////////////////
 466 // thread stack
 467 
 468 size_t os::Linux::min_stack_allowed  = 64 * K;
 469 
 470 // aarch64: pthread on aarch64 is always in floating stack mode
 471 bool os::Linux::supports_variable_stack_size() {  return true; }
 472 
 473 // return default stack size for thr_type
 474 size_t os::Linux::default_stack_size(os::ThreadType thr_type) {
 475   // default stack size (compiler thread needs larger stack)
 476   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
 477   return s;
 478 }
 479 
 480 size_t os::Linux::default_guard_size(os::ThreadType thr_type) {
 481   // Creating guard page is very expensive. Java thread has HotSpot
 482   // guard page, only enable glibc guard page for non-Java threads.
 483   return (thr_type == java_thread ? 0 : page_size());
 484 }
 485 
 486 // Java thread:
 487 //
 488 //   Low memory addresses
 489 //    +------------------------+
 490 //    |                        |\  JavaThread created by VM does not have glibc
 491 //    |    glibc guard page    | - guard, attached Java thread usually has
 492 //    |                        |/  1 page glibc guard.
 493 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
 494 //    |                        |\
 495 //    |  HotSpot Guard Pages   | - red and yellow pages
 496 //    |                        |/
 497 //    +------------------------+ JavaThread::stack_yellow_zone_base()
 498 //    |                        |\
 499 //    |      Normal Stack      | -
 500 //    |                        |/
 501 // P2 +------------------------+ Thread::stack_base()
 502 //
 503 // Non-Java thread:
 504 //
 505 //   Low memory addresses
 506 //    +------------------------+
 507 //    |                        |\
 508 //    |  glibc guard page      | - usually 1 page
 509 //    |                        |/
 510 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
 511 //    |                        |\
 512 //    |      Normal Stack      | -
 513 //    |                        |/
 514 // P2 +------------------------+ Thread::stack_base()
 515 //
 516 // ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from
 517 //    pthread_attr_getstack()
 518 
 519 static void current_stack_region(address * bottom, size_t * size) {
 520   if (os::is_primordial_thread()) {
 521      // primordial thread needs special handling because pthread_getattr_np()
 522      // may return bogus value.
 523      *bottom = os::Linux::initial_thread_stack_bottom();
 524      *size   = os::Linux::initial_thread_stack_size();
 525   } else {
 526      pthread_attr_t attr;
 527 
 528      int rslt = pthread_getattr_np(pthread_self(), &attr);
 529 
 530      // JVM needs to know exact stack location, abort if it fails
 531      if (rslt != 0) {
 532        if (rslt == ENOMEM) {
 533          vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np");
 534        } else {
 535          fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt));
 536        }
 537      }
 538 
 539      if (pthread_attr_getstack(&attr, (void **)bottom, size) != 0) {
 540          fatal("Can not locate current stack attributes!");
 541      }
 542 
 543      pthread_attr_destroy(&attr);
 544 
 545   }
 546   assert(os::current_stack_pointer() >= *bottom &&
 547          os::current_stack_pointer() < *bottom + *size, "just checking");
 548 }
 549 
 550 address os::current_stack_base() {
 551   address bottom;
 552   size_t size;
 553   current_stack_region(&bottom, &size);
 554   return (bottom + size);
 555 }
 556 
 557 size_t os::current_stack_size() {
 558   // stack size includes normal stack and HotSpot guard pages
 559   address bottom;
 560   size_t size;
 561   current_stack_region(&bottom, &size);
 562   return size;
 563 }
 564 
 565 /////////////////////////////////////////////////////////////////////////////
 566 // helper functions for fatal error handler
 567 
 568 
 569 void os::print_context(outputStream *st, void *context) {
 570   if (context == NULL) return;
 571 
 572   ucontext_t *uc = (ucontext_t*)context;
 573   st->print_cr("Registers:");
 574 
 575   for (int r = 0; r < 16; r++)
 576     st->print_cr(  "R%d=" INTPTR_FORMAT, r,  *((unsigned int*)&uc->uc_mcontext.arm_r0 + r) );
 577 
 578   st->cr();
 579 
 580   intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
 581   st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp));
 582   print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t));
 583   st->cr();
 584 
 585   // Note: it may be unsafe to inspect memory near pc. For example, pc may
 586   // point to garbage if entry point in an nmethod is corrupted. Leave
 587   // this at the end, and hope for the best.
 588   address pc = os::Linux::ucontext_get_pc(uc);
 589   st->print_cr("Instructions: (pc=" PTR_FORMAT ")", p2i(pc));
 590   print_hex_dump(st, pc - 32, pc + 32, sizeof(char));
 591 }
 592 
 593 void os::print_register_info(outputStream *st, void *context) {
 594   if (context == NULL) return;
 595 
 596   ucontext_t *uc = (ucontext_t*)context;
 597 
 598   st->print_cr("Register to memory mapping:");
 599   st->cr();
 600 
 601   for (int r = 0; r < 16; r++) {
 602     st->print(  "R%d=", r); print_location(st, *((unsigned int*)&uc->uc_mcontext.arm_r0 + r));
 603   }
 604   st->cr();
 605 }
 606 
 607 void os::setup_fpu() {
 608 }
 609 
 610 #ifndef PRODUCT
 611 void os::verify_stack_alignment() {
 612   assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");
 613 }
 614 #endif
 615 
 616 extern "C" {
 617   int SpinPause() {
 618     return 0;
 619   }
 620 
 621   void _Copy_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
 622     if (from > to) {
 623       jshort *end = from + count;
 624       while (from < end)
 625         *(to++) = *(from++);
 626     }
 627     else if (from < to) {
 628       jshort *end = from;
 629       from += count - 1;
 630       to   += count - 1;
 631       while (from >= end)
 632         *(to--) = *(from--);
 633     }
 634   }
 635   void _Copy_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
 636     if (from > to) {
 637       jint *end = from + count;
 638       while (from < end)
 639         *(to++) = *(from++);
 640     }
 641     else if (from < to) {
 642       jint *end = from;
 643       from += count - 1;
 644       to   += count - 1;
 645       while (from >= end)
 646         *(to--) = *(from--);
 647     }
 648   }
 649   void _Copy_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
 650     if (from > to) {
 651       jlong *end = from + count;
 652       while (from < end)
 653         os::atomic_copy64(from++, to++);
 654     }
 655     else if (from < to) {
 656       jlong *end = from;
 657       from += count - 1;
 658       to   += count - 1;
 659       while (from >= end)
 660         os::atomic_copy64(from--, to--);
 661     }
 662   }
 663 
 664   void _Copy_arrayof_conjoint_bytes(HeapWord* from,
 665                                     HeapWord* to,
 666                                     size_t    count) {
 667     memmove(to, from, count);
 668   }
 669   void _Copy_arrayof_conjoint_jshorts(HeapWord* from,
 670                                       HeapWord* to,
 671                                       size_t    count) {
 672     memmove(to, from, count * 2);
 673   }
 674   void _Copy_arrayof_conjoint_jints(HeapWord* from,
 675                                     HeapWord* to,
 676                                     size_t    count) {
 677     memmove(to, from, count * 4);
 678   }
 679   void _Copy_arrayof_conjoint_jlongs(HeapWord* from,
 680                                      HeapWord* to,
 681                                      size_t    count) {
 682     memmove(to, from, count * 8);
 683   }
 684 };