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