1 /* 2 * Copyright (c) 2017, 2024, 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 "precompiled.hpp" 26 #include "accessBackend.inline.hpp" 27 #include "gc/shared/collectedHeap.hpp" 28 #include "oops/oop.inline.hpp" 29 #include "runtime/javaThread.inline.hpp" 30 #include "runtime/mutexLocker.hpp" 31 #include "utilities/copy.hpp" 32 #include "utilities/debug.hpp" 33 #include "utilities/vmError.hpp" 34 35 #if defined(TARGET_COMPILER_gcc) 36 #define HIDDEN __attribute__ ((visibility ("hidden"))) 37 #else 38 #define HIDDEN 39 #endif 40 41 namespace AccessInternal { 42 // These forward copying calls to Copy without exposing the Copy type in headers unnecessarily 43 44 void arraycopy_arrayof_conjoint_oops(void* src, void* dst, size_t length) { 45 Copy::arrayof_conjoint_oops(reinterpret_cast<HeapWord*>(src), 46 reinterpret_cast<HeapWord*>(dst), length); 47 } 48 49 void arraycopy_conjoint_oops(oop* src, oop* dst, size_t length) { 50 Copy::conjoint_oops_atomic(src, dst, length); 51 } 52 53 void arraycopy_conjoint_oops(narrowOop* src, narrowOop* dst, size_t length) { 54 Copy::conjoint_oops_atomic(src, dst, length); 55 } 56 57 void arraycopy_disjoint_words(void* src, void* dst, size_t length) { 58 Copy::disjoint_words(reinterpret_cast<HeapWord*>(src), 59 reinterpret_cast<HeapWord*>(dst), length); 60 } 61 62 void arraycopy_disjoint_words_atomic(void* src, void* dst, size_t length) { 63 Copy::disjoint_words_atomic(reinterpret_cast<HeapWord*>(src), 64 reinterpret_cast<HeapWord*>(dst), length); 65 } 66 67 template<> HIDDEN 68 void arraycopy_conjoint<jboolean>(jboolean* src, jboolean* dst, size_t length) { 69 Copy::conjoint_jbytes(reinterpret_cast<jbyte*>(src), reinterpret_cast<jbyte*>(dst), length); 70 } 71 72 template<> HIDDEN 73 void arraycopy_conjoint<jbyte>(jbyte* src, jbyte* dst, size_t length) { 74 Copy::conjoint_jbytes(src, dst, length); 75 } 76 77 template<> HIDDEN 78 void arraycopy_conjoint<jchar>(jchar* src, jchar* dst, size_t length) { 79 Copy::conjoint_jshorts_atomic(reinterpret_cast<jshort*>(src), reinterpret_cast<jshort*>(dst), length); 80 } 81 82 template<> HIDDEN 83 void arraycopy_conjoint<jshort>(jshort* src, jshort* dst, size_t length) { 84 Copy::conjoint_jshorts_atomic(src, dst, length); 85 } 86 87 template<> HIDDEN 88 void arraycopy_conjoint<jint>(jint* src, jint* dst, size_t length) { 89 Copy::conjoint_jints_atomic(src, dst, length); 90 } 91 92 template<> HIDDEN 93 void arraycopy_conjoint<jfloat>(jfloat* src, jfloat* dst, size_t length) { 94 Copy::conjoint_jints_atomic(reinterpret_cast<jint*>(src), reinterpret_cast<jint*>(dst), length); 95 } 96 97 template<> HIDDEN 98 void arraycopy_conjoint<jlong>(jlong* src, jlong* dst, size_t length) { 99 Copy::conjoint_jlongs_atomic(src, dst, length); 100 } 101 102 template<> HIDDEN 103 void arraycopy_conjoint<jdouble>(jdouble* src, jdouble* dst, size_t length) { 104 Copy::conjoint_jlongs_atomic(reinterpret_cast<jlong*>(src), reinterpret_cast<jlong*>(dst), length); 105 } 106 107 template<> HIDDEN 108 void arraycopy_arrayof_conjoint<jbyte>(jbyte* src, jbyte* dst, size_t length) { 109 Copy::arrayof_conjoint_jbytes(reinterpret_cast<HeapWord*>(src), 110 reinterpret_cast<HeapWord*>(dst), 111 length); 112 } 113 114 template<> HIDDEN 115 void arraycopy_arrayof_conjoint<jshort>(jshort* src, jshort* dst, size_t length) { 116 Copy::arrayof_conjoint_jshorts(reinterpret_cast<HeapWord*>(src), 117 reinterpret_cast<HeapWord*>(dst), 118 length); 119 } 120 121 template<> HIDDEN 122 void arraycopy_arrayof_conjoint<jint>(jint* src, jint* dst, size_t length) { 123 Copy::arrayof_conjoint_jints(reinterpret_cast<HeapWord*>(src), 124 reinterpret_cast<HeapWord*>(dst), 125 length); 126 } 127 128 template<> HIDDEN 129 void arraycopy_arrayof_conjoint<jlong>(jlong* src, jlong* dst, size_t length) { 130 Copy::arrayof_conjoint_jlongs(reinterpret_cast<HeapWord*>(src), 131 reinterpret_cast<HeapWord*>(dst), 132 length); 133 } 134 135 template<> HIDDEN 136 void arraycopy_conjoint<void>(void* src, void* dst, size_t length) { 137 Copy::conjoint_jbytes(reinterpret_cast<jbyte*>(src), 138 reinterpret_cast<jbyte*>(dst), 139 length); 140 } 141 142 template<> HIDDEN 143 void arraycopy_conjoint_atomic<jbyte>(jbyte* src, jbyte* dst, size_t length) { 144 Copy::conjoint_jbytes_atomic(src, dst, length); 145 } 146 147 template<> HIDDEN 148 void arraycopy_conjoint_atomic<jshort>(jshort* src, jshort* dst, size_t length) { 149 Copy::conjoint_jshorts_atomic(src, dst, length); 150 } 151 152 template<> HIDDEN 153 void arraycopy_conjoint_atomic<jint>(jint* src, jint* dst, size_t length) { 154 Copy::conjoint_jints_atomic(src, dst, length); 155 } 156 157 template<> HIDDEN 158 void arraycopy_conjoint_atomic<jlong>(jlong* src, jlong* dst, size_t length) { 159 Copy::conjoint_jlongs_atomic(src, dst, length); 160 } 161 162 template<> HIDDEN 163 void arraycopy_conjoint_atomic<void>(void* src, void* dst, size_t length) { 164 Copy::conjoint_memory_atomic(src, dst, length); 165 } 166 167 #ifdef ASSERT 168 void check_access_thread_state() { 169 if (VMError::is_error_reported() || DebuggingContext::is_enabled()) { 170 return; 171 } 172 173 Thread* thread = Thread::current(); 174 if (!thread->is_Java_thread()) { 175 return; 176 } 177 178 JavaThread* java_thread = JavaThread::cast(thread); 179 JavaThreadState state = java_thread->thread_state(); 180 assert(state == _thread_in_vm || state == _thread_in_Java || state == _thread_new, 181 "Wrong thread state for accesses: %d", (int)state); 182 } 183 #endif 184 }