1 /*
  2  * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
  4  * Copyright (c) 2021, Azul Systems, Inc. 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 #include "asm/macroAssembler.hpp"
 28 #include "classfile/classLoader.hpp"
 29 #include "classfile/vmSymbols.hpp"
 30 #include "code/codeCache.hpp"
 31 #include "code/vtableStubs.hpp"
 32 #include "interpreter/interpreter.hpp"
 33 #include "jvm.h"
 34 #include "logging/log.hpp"
 35 #include "memory/allocation.inline.hpp"
 36 #include "os_bsd.hpp"
 37 #include "os_posix.hpp"
 38 #include "prims/jniFastGetField.hpp"
 39 #include "prims/jvm_misc.hpp"
 40 #include "runtime/arguments.hpp"
 41 #include "runtime/frame.inline.hpp"
 42 #include "runtime/interfaceSupport.inline.hpp"
 43 #include "runtime/java.hpp"
 44 #include "runtime/javaCalls.hpp"
 45 #include "runtime/javaThread.hpp"
 46 #include "runtime/mutexLocker.hpp"
 47 #include "runtime/osThread.hpp"
 48 #include "runtime/safepointMechanism.hpp"
 49 #include "runtime/sharedRuntime.hpp"
 50 #include "runtime/stubRoutines.hpp"
 51 #include "runtime/timer.hpp"
 52 #include "signals_posix.hpp"
 53 #include "utilities/align.hpp"
 54 #include "utilities/events.hpp"
 55 #include "utilities/vmError.hpp"
 56 
 57 // put OS-includes here
 58 # include <sys/types.h>
 59 # include <sys/mman.h>
 60 # include <pthread.h>
 61 # include <signal.h>
 62 # include <errno.h>
 63 # include <dlfcn.h>
 64 # include <stdlib.h>
 65 # include <stdio.h>
 66 # include <unistd.h>
 67 # include <sys/resource.h>
 68 # include <sys/stat.h>
 69 # include <sys/time.h>
 70 # include <sys/utsname.h>
 71 # include <sys/socket.h>
 72 # include <sys/wait.h>
 73 # include <pwd.h>
 74 # include <poll.h>
 75 #ifndef __OpenBSD__
 76 # include <ucontext.h>
 77 #endif
 78 
 79 #if !defined(__APPLE__) && !defined(__NetBSD__)
 80 # include <pthread_np.h>
 81 #endif
 82 
 83 #define SPELL_REG_SP "sp"
 84 #define SPELL_REG_FP "fp"
 85 
 86 #ifdef __APPLE__
 87 // see darwin-xnu/osfmk/mach/arm/_structs.h
 88 
 89 // 10.5 UNIX03 member name prefixes
 90 #define DU3_PREFIX(s, m) __ ## s.__ ## m
 91 #endif
 92 
 93 #define context_x    uc_mcontext->DU3_PREFIX(ss,x)
 94 #define context_fp   uc_mcontext->DU3_PREFIX(ss,fp)
 95 #define context_lr   uc_mcontext->DU3_PREFIX(ss,lr)
 96 #define context_sp   uc_mcontext->DU3_PREFIX(ss,sp)
 97 #define context_pc   uc_mcontext->DU3_PREFIX(ss,pc)
 98 #define context_cpsr uc_mcontext->DU3_PREFIX(ss,cpsr)
 99 #define context_esr  uc_mcontext->DU3_PREFIX(es,esr)
100 
101 address os::current_stack_pointer() {
102 #if defined(__clang__) || defined(__llvm__)
103   void *sp;
104   __asm__("mov %0, " SPELL_REG_SP : "=r"(sp));
105   return (address) sp;
106 #else
107   register void *sp __asm__ (SPELL_REG_SP);
108   return (address) sp;
109 #endif
110 }
111 
112 char* os::non_memory_address_word() {
113   // Must never look like an address returned by reserve_memory,
114   // even in its subfields (as defined by the CPU immediate fields,
115   // if the CPU splits constants across multiple instructions).
116 
117   // the return value used in computation of Universe::non_oop_word(), which
118   // is loaded by cpu/aarch64 by MacroAssembler::movptr(Register, uintptr_t)
119   return (char*) 0xffffffffffff;
120 }
121 
122 address os::Posix::ucontext_get_pc(const ucontext_t * uc) {
123   return (address)uc->context_pc;
124 }
125 
126 void os::Posix::ucontext_set_pc(ucontext_t * uc, address pc) {
127   uc->context_pc = (intptr_t)pc ;
128 }
129 
130 intptr_t* os::Bsd::ucontext_get_sp(const ucontext_t * uc) {
131   return (intptr_t*)uc->context_sp;
132 }
133 
134 intptr_t* os::Bsd::ucontext_get_fp(const ucontext_t * uc) {
135   return (intptr_t*)uc->context_fp;
136 }
137 
138 address os::fetch_frame_from_context(const void* ucVoid,
139                     intptr_t** ret_sp, intptr_t** ret_fp) {
140 
141   address epc;
142   const ucontext_t* uc = (const ucontext_t*)ucVoid;
143 
144   if (uc != nullptr) {
145     epc = os::Posix::ucontext_get_pc(uc);
146     if (ret_sp) *ret_sp = os::Bsd::ucontext_get_sp(uc);
147     if (ret_fp) *ret_fp = os::Bsd::ucontext_get_fp(uc);
148   } else {
149     epc = nullptr;
150     if (ret_sp) *ret_sp = (intptr_t *)nullptr;
151     if (ret_fp) *ret_fp = (intptr_t *)nullptr;
152   }
153 
154   return epc;
155 }
156 
157 frame os::fetch_frame_from_context(const void* ucVoid) {
158   intptr_t* sp;
159   intptr_t* fp;
160   address epc = fetch_frame_from_context(ucVoid, &sp, &fp);
161   if (!is_readable_pointer(epc)) {
162     // Try to recover from calling into bad memory
163     // Assume new frame has not been set up, the same as
164     // compiled frame stack bang
165     return fetch_compiled_frame_from_context(ucVoid);
166   }
167   return frame(sp, fp, epc);
168 }
169 
170 frame os::fetch_compiled_frame_from_context(const void* ucVoid) {
171   const ucontext_t* uc = (const ucontext_t*)ucVoid;
172   // In compiled code, the stack banging is performed before LR
173   // has been saved in the frame.  LR is live, and SP and FP
174   // belong to the caller.
175   intptr_t* fp = os::Bsd::ucontext_get_fp(uc);
176   intptr_t* sp = os::Bsd::ucontext_get_sp(uc);
177   address pc = (address)(uc->context_lr
178                          - NativeInstruction::instruction_size);
179   return frame(sp, fp, pc);
180 }
181 
182 // JVM compiled with -fno-omit-frame-pointer, so RFP is saved on the stack.
183 frame os::get_sender_for_C_frame(frame* fr) {
184   return frame(fr->sender_sp(), fr->link(), fr->sender_pc());
185 }
186 
187 NOINLINE frame os::current_frame() {
188   intptr_t *fp = *(intptr_t **)__builtin_frame_address(0);
189   frame myframe((intptr_t*)os::current_stack_pointer(),
190                 (intptr_t*)fp,
191                 CAST_FROM_FN_PTR(address, os::current_frame));
192   if (os::is_first_C_frame(&myframe)) {
193     // stack is not walkable
194     return frame();
195   } else {
196     return os::get_sender_for_C_frame(&myframe);
197   }
198 }
199 
200 bool PosixSignals::pd_hotspot_signal_handler(int sig, siginfo_t* info,
201                                              ucontext_t* uc, JavaThread* thread) {
202   // Enable WXWrite: this function is called by the signal handler at arbitrary
203   // point of execution.
204   ThreadWXEnable wx(WXWrite, thread);
205 
206   // decide if this trap can be handled by a stub
207   address stub = nullptr;
208 
209   address pc          = nullptr;
210 
211   //%note os_trap_1
212   if (info != nullptr && uc != nullptr && thread != nullptr) {
213     pc = (address) os::Posix::ucontext_get_pc(uc);
214 
215     // Handle ALL stack overflow variations here
216     if (sig == SIGSEGV || sig == SIGBUS) {
217       address addr = (address) info->si_addr;
218 
219       // Make sure the high order byte is sign extended, as it may be masked away by the hardware.
220       if ((uintptr_t(addr) & (uintptr_t(1) << 55)) != 0) {
221         addr = address(uintptr_t(addr) | (uintptr_t(0xFF) << 56));
222       }
223 
224       // check if fault address is within thread stack
225       if (thread->is_in_full_stack(addr)) {
226         // stack overflow
227         if (os::Posix::handle_stack_overflow(thread, addr, pc, uc, &stub)) {
228           return true; // continue
229         }
230       }
231     }
232 
233     // We test if stub is already set (by the stack overflow code
234     // above) so it is not overwritten by the code that follows. This
235     // check is not required on other platforms, because on other
236     // platforms we check for SIGSEGV only or SIGBUS only, where here
237     // we have to check for both SIGSEGV and SIGBUS.
238     if (thread->thread_state() == _thread_in_Java && stub == nullptr) {
239       // Java thread running in Java code => find exception handler if any
240       // a fault inside compiled code, the interpreter, or a stub
241 
242       // Handle signal from NativeJump::patch_verified_entry().
243       if ((sig == SIGILL)
244           && nativeInstruction_at(pc)->is_sigill_not_entrant()) {
245         if (TraceTraps) {
246           tty->print_cr("trap: not_entrant");
247         }
248         stub = SharedRuntime::get_handle_wrong_method_stub();
249       } else if ((sig == SIGSEGV || sig == SIGBUS) && SafepointMechanism::is_poll_address((address)info->si_addr)) {
250         stub = SharedRuntime::get_poll_stub(pc);
251 #if defined(__APPLE__)
252       // 32-bit Darwin reports a SIGBUS for nearly all memory access exceptions.
253       // 64-bit Darwin may also use a SIGBUS (seen with compressed oops).
254       // Catching SIGBUS here prevents the implicit SIGBUS null check below from
255       // being called, so only do so if the implicit null check is not necessary.
256       } else if (sig == SIGBUS && !MacroAssembler::uses_implicit_null_check(info->si_addr)) {
257 #else
258       } else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) {
259 #endif
260         // BugId 4454115: A read from a MappedByteBuffer can fault
261         // here if the underlying file has been truncated.
262         // Do not crash the VM in such a case.
263         CodeBlob* cb = CodeCache::find_blob(pc);
264         nmethod* nm = (cb != nullptr) ? cb->as_nmethod_or_null() : nullptr;
265         bool is_unsafe_memory_access = (thread->doing_unsafe_access() && UnsafeMemoryAccess::contains_pc(pc));
266         if ((nm != nullptr && nm->has_unsafe_access()) || is_unsafe_memory_access) {
267           address next_pc = pc + NativeCall::instruction_size;
268           if (is_unsafe_memory_access) {
269             next_pc = UnsafeMemoryAccess::page_error_continue_pc(pc);
270           }
271           stub = SharedRuntime::handle_unsafe_access(thread, next_pc);
272         }
273       } else if (sig == SIGILL && nativeInstruction_at(pc)->is_stop()) {
274         // A pointer to the message will have been placed in x0
275         const char *detail_msg = (const char *)(uc->uc_mcontext->DU3_PREFIX(ss,x[0]));
276         const char *msg = "stop";
277         if (TraceTraps) {
278           tty->print_cr("trap: %s: (SIGILL)", msg);
279         }
280 
281         // End life with a fatal error, message and detail message and the context.
282         // Note: no need to do any post-processing here (e.g. signal chaining)
283         VMError::report_and_die(thread, uc, nullptr, 0, msg, "%s", detail_msg);
284         ShouldNotReachHere();
285 
286       } else if (sig == SIGFPE &&
287           (info->si_code == FPE_INTDIV || info->si_code == FPE_FLTDIV)) {
288         stub =
289           SharedRuntime::
290           continuation_for_implicit_exception(thread,
291                                               pc,
292                                               SharedRuntime::
293                                               IMPLICIT_DIVIDE_BY_ZERO);
294       } else if ((sig == SIGSEGV || sig == SIGBUS) &&
295                  MacroAssembler::uses_implicit_null_check(info->si_addr)) {
296           // Determination of interpreter/vtable stub/compiled code null exception
297           stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
298       }
299     } else if ((thread->thread_state() == _thread_in_vm ||
300                  thread->thread_state() == _thread_in_native) &&
301                sig == SIGBUS && /* info->si_code == BUS_OBJERR && */
302                thread->doing_unsafe_access()) {
303       address next_pc = pc + NativeCall::instruction_size;
304       if (UnsafeMemoryAccess::contains_pc(pc)) {
305         next_pc = UnsafeMemoryAccess::page_error_continue_pc(pc);
306       }
307       stub = SharedRuntime::handle_unsafe_access(thread, next_pc);
308     }
309 
310     // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
311     // and the heap gets shrunk before the field access.
312     if ((sig == SIGSEGV) || (sig == SIGBUS)) {
313       address addr = JNI_FastGetField::find_slowcase_pc(pc);
314       if (addr != (address)-1) {
315         stub = addr;
316       }
317     }
318   }
319 
320   if (stub != nullptr) {
321     // save all thread context in case we need to restore it
322     if (thread != nullptr) thread->set_saved_exception_pc(pc);
323 
324     os::Posix::ucontext_set_pc(uc, stub);
325     return true;
326   }
327 
328   return false; // Mute compiler
329 }
330 
331 void os::Bsd::init_thread_fpu_state(void) {
332 }
333 
334 ////////////////////////////////////////////////////////////////////////////////
335 // thread stack
336 
337 // Minimum usable stack sizes required to get to user code. Space for
338 // HotSpot guard pages is added later.
339 size_t os::_compiler_thread_min_stack_allowed = 72 * K;
340 size_t os::_java_thread_min_stack_allowed = 72 * K;
341 size_t os::_vm_internal_thread_min_stack_allowed = 72 * K;
342 
343 // return default stack size for thr_type
344 size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
345   // default stack size (compiler thread needs larger stack)
346   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
347   return s;
348 }
349 void os::current_stack_base_and_size(address* base, size_t* size) {
350   address bottom;
351 #ifdef __APPLE__
352   pthread_t self = pthread_self();
353   *base = (address) pthread_get_stackaddr_np(self);
354   *size = pthread_get_stacksize_np(self);
355   bottom = *base - *size;
356 #elif defined(__OpenBSD__)
357   stack_t ss;
358   int rslt = pthread_stackseg_np(pthread_self(), &ss);
359 
360   if (rslt != 0)
361     fatal("pthread_stackseg_np failed with error = %d", rslt);
362 
363   *base = (address) ss.ss_sp;
364   *size = ss.ss_size;
365   bottom = *base - *size;
366 #else
367   pthread_attr_t attr;
368 
369   int rslt = pthread_attr_init(&attr);
370 
371   // JVM needs to know exact stack location, abort if it fails
372   if (rslt != 0)
373     fatal("pthread_attr_init failed with error = %d", rslt);
374 
375   rslt = pthread_attr_get_np(pthread_self(), &attr);
376 
377   if (rslt != 0)
378     fatal("pthread_attr_get_np failed with error = %d", rslt);
379 
380   if (pthread_attr_getstackaddr(&attr, (void **)&bottom) != 0 ||
381       pthread_attr_getstacksize(&attr, size) != 0) {
382     fatal("Can not locate current stack attributes!");
383   }
384 
385   *base = bottom + *size;
386 
387   pthread_attr_destroy(&attr);
388 #endif
389   assert(os::current_stack_pointer() >= bottom &&
390          os::current_stack_pointer() < *base, "just checking");
391 }
392 
393 /////////////////////////////////////////////////////////////////////////////
394 // helper functions for fatal error handler
395 
396 void os::print_context(outputStream *st, const void *context) {
397   if (context == nullptr) return;
398 
399   const ucontext_t *uc = (const ucontext_t*)context;
400 
401   st->print_cr("Registers:");
402   st->print( " x0=" INTPTR_FORMAT, (intptr_t)uc->context_x[ 0]);
403   st->print("  x1=" INTPTR_FORMAT, (intptr_t)uc->context_x[ 1]);
404   st->print("  x2=" INTPTR_FORMAT, (intptr_t)uc->context_x[ 2]);
405   st->print("  x3=" INTPTR_FORMAT, (intptr_t)uc->context_x[ 3]);
406   st->cr();
407   st->print( " x4=" INTPTR_FORMAT, (intptr_t)uc->context_x[ 4]);
408   st->print("  x5=" INTPTR_FORMAT, (intptr_t)uc->context_x[ 5]);
409   st->print("  x6=" INTPTR_FORMAT, (intptr_t)uc->context_x[ 6]);
410   st->print("  x7=" INTPTR_FORMAT, (intptr_t)uc->context_x[ 7]);
411   st->cr();
412   st->print( " x8=" INTPTR_FORMAT, (intptr_t)uc->context_x[ 8]);
413   st->print("  x9=" INTPTR_FORMAT, (intptr_t)uc->context_x[ 9]);
414   st->print(" x10=" INTPTR_FORMAT, (intptr_t)uc->context_x[10]);
415   st->print(" x11=" INTPTR_FORMAT, (intptr_t)uc->context_x[11]);
416   st->cr();
417   st->print( "x12=" INTPTR_FORMAT, (intptr_t)uc->context_x[12]);
418   st->print(" x13=" INTPTR_FORMAT, (intptr_t)uc->context_x[13]);
419   st->print(" x14=" INTPTR_FORMAT, (intptr_t)uc->context_x[14]);
420   st->print(" x15=" INTPTR_FORMAT, (intptr_t)uc->context_x[15]);
421   st->cr();
422   st->print( "x16=" INTPTR_FORMAT, (intptr_t)uc->context_x[16]);
423   st->print(" x17=" INTPTR_FORMAT, (intptr_t)uc->context_x[17]);
424   st->print(" x18=" INTPTR_FORMAT, (intptr_t)uc->context_x[18]);
425   st->print(" x19=" INTPTR_FORMAT, (intptr_t)uc->context_x[19]);
426   st->cr();
427   st->print( "x20=" INTPTR_FORMAT, (intptr_t)uc->context_x[20]);
428   st->print(" x21=" INTPTR_FORMAT, (intptr_t)uc->context_x[21]);
429   st->print(" x22=" INTPTR_FORMAT, (intptr_t)uc->context_x[22]);
430   st->print(" x23=" INTPTR_FORMAT, (intptr_t)uc->context_x[23]);
431   st->cr();
432   st->print( "x24=" INTPTR_FORMAT, (intptr_t)uc->context_x[24]);
433   st->print(" x25=" INTPTR_FORMAT, (intptr_t)uc->context_x[25]);
434   st->print(" x26=" INTPTR_FORMAT, (intptr_t)uc->context_x[26]);
435   st->print(" x27=" INTPTR_FORMAT, (intptr_t)uc->context_x[27]);
436   st->cr();
437   st->print( "x28=" INTPTR_FORMAT, (intptr_t)uc->context_x[28]);
438   st->print("  fp=" INTPTR_FORMAT, (intptr_t)uc->context_fp);
439   st->print("  lr=" INTPTR_FORMAT, (intptr_t)uc->context_lr);
440   st->print("  sp=" INTPTR_FORMAT, (intptr_t)uc->context_sp);
441   st->cr();
442   st->print(  "pc=" INTPTR_FORMAT,  (intptr_t)uc->context_pc);
443   st->print(" cpsr=" INTPTR_FORMAT, (intptr_t)uc->context_cpsr);
444   st->cr();
445 }
446 
447 void os::print_register_info(outputStream *st, const void *context, int& continuation) {
448   const int register_count = 29 /* x0-x28 */ + 3 /* fp, lr, sp */;
449   int n = continuation;
450   assert(n >= 0 && n <= register_count, "Invalid continuation value");
451   if (context == nullptr || n == register_count) {
452     return;
453   }
454 
455   const ucontext_t *uc = (const ucontext_t*)context;
456   while (n < register_count) {
457     // Update continuation with next index before printing location
458     continuation = n + 1;
459     switch (n) {
460     case 29:
461       st->print(" fp="); print_location(st, uc->context_fp);
462       break;
463     case 30:
464       st->print(" lr="); print_location(st, uc->context_lr);
465       break;
466     case 31:
467       st->print(" sp="); print_location(st, uc->context_sp);
468       break;
469     default:
470       st->print("x%-2d=",n); print_location(st, uc->context_x[n]);
471       break;
472     }
473     ++n;
474   }
475 }
476 
477 void os::setup_fpu() {
478 }
479 
480 #ifndef PRODUCT
481 void os::verify_stack_alignment() {
482   assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");
483 }
484 #endif
485 
486 int os::extra_bang_size_in_bytes() {
487   // AArch64 does not require the additional stack bang.
488   return 0;
489 }
490 
491 void os::current_thread_enable_wx(WXMode mode) {
492   pthread_jit_write_protect_np(mode == WXExec);
493 }
494 
495 static inline void atomic_copy64(const volatile void *src, volatile void *dst) {
496   *(jlong *) dst = *(const jlong *) src;
497 }
498 
499 extern "C" {
500   // needs local assembler label '1:' to avoid trouble when using linktime optimization
501   int SpinPause() {
502     // We don't use StubRoutines::aarch64::spin_wait stub in order to
503     // avoid a costly call to os::current_thread_enable_wx() on MacOS.
504     // We should return 1 if SpinPause is implemented, and since there
505     // will be a sequence of 11 instructions for NONE and YIELD and 12
506     // instructions for NOP and ISB, SpinPause will always return 1.
507     uint64_t br_dst;
508     const int instructions_per_case = 2;
509     int64_t off = VM_Version::spin_wait_desc().inst() * instructions_per_case * Assembler::instruction_size;
510 
511     assert(VM_Version::spin_wait_desc().inst() >= SpinWait::NONE &&
512            VM_Version::spin_wait_desc().inst() <= SpinWait::YIELD, "must be");
513     assert(-1 == SpinWait::NONE,  "must be");
514     assert( 0 == SpinWait::NOP,   "must be");
515     assert( 1 == SpinWait::ISB,   "must be");
516     assert( 2 == SpinWait::YIELD, "must be");
517 
518     asm volatile(
519         "  adr  %[d], 20          \n" // 20 == PC here + 5 instructions => address
520                                       // to entry for case SpinWait::NOP
521         "  add  %[d], %[d], %[o]  \n"
522         "  br   %[d]              \n"
523         "  b    1f                \n" // case SpinWait::NONE  (-1)
524         "  nop                    \n" // padding
525         "  nop                    \n" // case SpinWait::NOP   ( 0)
526         "  b    1f                \n"
527         "  isb                    \n" // case SpinWait::ISB   ( 1)
528         "  b    1f                \n"
529         "  yield                  \n" // case SpinWait::YIELD ( 2)
530         "1:        \n"
531         : [d]"=&r"(br_dst)
532         : [o]"r"(off)
533         : "memory");
534     return 1;
535   }
536 
537   void _Copy_conjoint_jshorts_atomic(const jshort* from, jshort* to, size_t count) {
538     if (from > to) {
539       const jshort *end = from + count;
540       while (from < end)
541         *(to++) = *(from++);
542     }
543     else if (from < to) {
544       const jshort *end = from;
545       from += count - 1;
546       to   += count - 1;
547       while (from >= end)
548         *(to--) = *(from--);
549     }
550   }
551   void _Copy_conjoint_jints_atomic(const jint* from, jint* to, size_t count) {
552     if (from > to) {
553       const jint *end = from + count;
554       while (from < end)
555         *(to++) = *(from++);
556     }
557     else if (from < to) {
558       const jint *end = from;
559       from += count - 1;
560       to   += count - 1;
561       while (from >= end)
562         *(to--) = *(from--);
563     }
564   }
565 
566   void _Copy_conjoint_jlongs_atomic(const jlong* from, jlong* to, size_t count) {
567     if (from > to) {
568       const jlong *end = from + count;
569       while (from < end)
570         atomic_copy64(from++, to++);
571     }
572     else if (from < to) {
573       const jlong *end = from;
574       from += count - 1;
575       to   += count - 1;
576       while (from >= end)
577         atomic_copy64(from--, to--);
578     }
579   }
580 
581   void _Copy_arrayof_conjoint_bytes(const HeapWord* from,
582                                     HeapWord* to,
583                                     size_t    count) {
584     memmove(to, from, count);
585   }
586   void _Copy_arrayof_conjoint_jshorts(const HeapWord* from,
587                                       HeapWord* to,
588                                       size_t    count) {
589     memmove(to, from, count * 2);
590   }
591   void _Copy_arrayof_conjoint_jints(const HeapWord* from,
592                                     HeapWord* to,
593                                     size_t    count) {
594     memmove(to, from, count * 4);
595   }
596   void _Copy_arrayof_conjoint_jlongs(const HeapWord* from,
597                                      HeapWord* to,
598                                      size_t    count) {
599     memmove(to, from, count * 8);
600   }
601 };