1 /* 2 * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "accessBackend.inline.hpp" 26 #include "gc/shared/collectedHeap.hpp" 27 #include "oops/oop.inline.hpp" 28 #include "runtime/javaThread.inline.hpp" 29 #include "runtime/mutexLocker.hpp" 30 #include "utilities/copy.hpp" 31 #include "utilities/debug.hpp" 32 #include "utilities/vmError.hpp" 33 34 #if defined(TARGET_COMPILER_gcc) 35 #define HIDDEN __attribute__ ((visibility ("hidden"))) 36 #else 37 #define HIDDEN 38 #endif 39 40 namespace AccessInternal { 41 // These forward copying calls to Copy without exposing the Copy type in headers unnecessarily 42 43 void arraycopy_arrayof_conjoint_oops(void* src, void* dst, size_t length) { 44 Copy::arrayof_conjoint_oops(reinterpret_cast<HeapWord*>(src), 45 reinterpret_cast<HeapWord*>(dst), length); 46 } 47 48 void arraycopy_conjoint_oops(oop* src, oop* dst, size_t length) { 49 Copy::conjoint_oops_atomic(src, dst, length); 50 } 51 52 void arraycopy_conjoint_oops(narrowOop* src, narrowOop* dst, size_t length) { 53 Copy::conjoint_oops_atomic(src, dst, length); 54 } 55 56 void arraycopy_disjoint_words(void* src, void* dst, size_t length) { 57 Copy::disjoint_words(reinterpret_cast<HeapWord*>(src), 58 reinterpret_cast<HeapWord*>(dst), length); 59 } 60 61 void arraycopy_disjoint_words_atomic(void* src, void* dst, size_t length) { 62 Copy::disjoint_words_atomic(reinterpret_cast<HeapWord*>(src), 63 reinterpret_cast<HeapWord*>(dst), length); 64 } 65 66 template<> HIDDEN 67 void arraycopy_conjoint<jboolean>(jboolean* src, jboolean* dst, size_t length) { 68 Copy::conjoint_jbytes(reinterpret_cast<jbyte*>(src), reinterpret_cast<jbyte*>(dst), length); 69 } 70 71 template<> HIDDEN 72 void arraycopy_conjoint<jbyte>(jbyte* src, jbyte* dst, size_t length) { 73 Copy::conjoint_jbytes(src, dst, length); 74 } 75 76 template<> HIDDEN 77 void arraycopy_conjoint<jchar>(jchar* src, jchar* dst, size_t length) { 78 Copy::conjoint_jshorts_atomic(reinterpret_cast<jshort*>(src), reinterpret_cast<jshort*>(dst), length); 79 } 80 81 template<> HIDDEN 82 void arraycopy_conjoint<jshort>(jshort* src, jshort* dst, size_t length) { 83 Copy::conjoint_jshorts_atomic(src, dst, length); 84 } 85 86 template<> HIDDEN 87 void arraycopy_conjoint<jint>(jint* src, jint* dst, size_t length) { 88 Copy::conjoint_jints_atomic(src, dst, length); 89 } 90 91 template<> HIDDEN 92 void arraycopy_conjoint<jfloat>(jfloat* src, jfloat* dst, size_t length) { 93 Copy::conjoint_jints_atomic(reinterpret_cast<jint*>(src), reinterpret_cast<jint*>(dst), length); 94 } 95 96 template<> HIDDEN 97 void arraycopy_conjoint<jlong>(jlong* src, jlong* dst, size_t length) { 98 Copy::conjoint_jlongs_atomic(src, dst, length); 99 } 100 101 template<> HIDDEN 102 void arraycopy_conjoint<jdouble>(jdouble* src, jdouble* dst, size_t length) { 103 Copy::conjoint_jlongs_atomic(reinterpret_cast<jlong*>(src), reinterpret_cast<jlong*>(dst), length); 104 } 105 106 template<> HIDDEN 107 void arraycopy_arrayof_conjoint<jbyte>(jbyte* src, jbyte* dst, size_t length) { 108 Copy::arrayof_conjoint_jbytes(reinterpret_cast<HeapWord*>(src), 109 reinterpret_cast<HeapWord*>(dst), 110 length); 111 } 112 113 template<> HIDDEN 114 void arraycopy_arrayof_conjoint<jshort>(jshort* src, jshort* dst, size_t length) { 115 Copy::arrayof_conjoint_jshorts(reinterpret_cast<HeapWord*>(src), 116 reinterpret_cast<HeapWord*>(dst), 117 length); 118 } 119 120 template<> HIDDEN 121 void arraycopy_arrayof_conjoint<jint>(jint* src, jint* dst, size_t length) { 122 Copy::arrayof_conjoint_jints(reinterpret_cast<HeapWord*>(src), 123 reinterpret_cast<HeapWord*>(dst), 124 length); 125 } 126 127 template<> HIDDEN 128 void arraycopy_arrayof_conjoint<jlong>(jlong* src, jlong* dst, size_t length) { 129 Copy::arrayof_conjoint_jlongs(reinterpret_cast<HeapWord*>(src), 130 reinterpret_cast<HeapWord*>(dst), 131 length); 132 } 133 134 template<> HIDDEN 135 void arraycopy_conjoint<void>(void* src, void* dst, size_t length) { 136 Copy::conjoint_jbytes(reinterpret_cast<jbyte*>(src), 137 reinterpret_cast<jbyte*>(dst), 138 length); 139 } 140 141 template<> HIDDEN 142 void arraycopy_conjoint_atomic<jbyte>(jbyte* src, jbyte* dst, size_t length) { 143 Copy::conjoint_jbytes_atomic(src, dst, length); 144 } 145 146 template<> HIDDEN 147 void arraycopy_conjoint_atomic<jshort>(jshort* src, jshort* dst, size_t length) { 148 Copy::conjoint_jshorts_atomic(src, dst, length); 149 } 150 151 template<> HIDDEN 152 void arraycopy_conjoint_atomic<jint>(jint* src, jint* dst, size_t length) { 153 Copy::conjoint_jints_atomic(src, dst, length); 154 } 155 156 template<> HIDDEN 157 void arraycopy_conjoint_atomic<jlong>(jlong* src, jlong* dst, size_t length) { 158 Copy::conjoint_jlongs_atomic(src, dst, length); 159 } 160 161 template<> HIDDEN 162 void arraycopy_conjoint_atomic<void>(void* src, void* dst, size_t length) { 163 Copy::conjoint_memory_atomic(src, dst, length); 164 } 165 166 void value_copy_internal(void* src, void* dst, size_t length) { 167 Copy::copy_value_content(src, dst, length); 168 } 169 170 #ifdef ASSERT 171 void check_access_thread_state() { 172 if (VMError::is_error_reported() || DebuggingContext::is_enabled()) { 173 return; 174 } 175 176 Thread* thread = Thread::current(); 177 if (!thread->is_Java_thread()) { 178 return; 179 } 180 181 JavaThread* java_thread = JavaThread::cast(thread); 182 JavaThreadState state = java_thread->thread_state(); 183 assert(state == _thread_in_vm || state == _thread_in_Java || state == _thread_new, 184 "Wrong thread state for accesses: %d", (int)state); 185 } 186 #endif 187 }