Path: blob/master/src/hotspot/cpu/zero/copy_zero.hpp
40930 views
/*1* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.2* Copyright 2007 Red Hat, Inc.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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#ifndef CPU_ZERO_COPY_ZERO_HPP26#define CPU_ZERO_COPY_ZERO_HPP2728// Inline functions for memory copy and fill.2930static void pd_conjoint_words(const HeapWord* from, HeapWord* to, size_t count) {31memmove(to, from, count * HeapWordSize);32}3334static void pd_disjoint_words(const HeapWord* from, HeapWord* to, size_t count) {35switch (count) {36case 8: to[7] = from[7];37case 7: to[6] = from[6];38case 6: to[5] = from[5];39case 5: to[4] = from[4];40case 4: to[3] = from[3];41case 3: to[2] = from[2];42case 2: to[1] = from[1];43case 1: to[0] = from[0];44case 0: break;45default:46memcpy(to, from, count * HeapWordSize);47break;48}49}5051static void pd_disjoint_words_atomic(const HeapWord* from,52HeapWord* to,53size_t count) {54switch (count) {55case 8: to[7] = from[7];56case 7: to[6] = from[6];57case 6: to[5] = from[5];58case 5: to[4] = from[4];59case 4: to[3] = from[3];60case 3: to[2] = from[2];61case 2: to[1] = from[1];62case 1: to[0] = from[0];63case 0: break;64default:65while (count-- > 0) {66*to++ = *from++;67}68break;69}70}7172static void pd_aligned_conjoint_words(const HeapWord* from,73HeapWord* to,74size_t count) {75memmove(to, from, count * HeapWordSize);76}7778static void pd_aligned_disjoint_words(const HeapWord* from,79HeapWord* to,80size_t count) {81pd_disjoint_words(from, to, count);82}8384static void pd_conjoint_bytes(const void* from, void* to, size_t count) {85memmove(to, from, count);86}8788static void pd_conjoint_bytes_atomic(const void* from, void* to, size_t count) {89memmove(to, from, count);90}9192static void pd_conjoint_jshorts_atomic(const jshort* from, jshort* to, size_t count) {93_Copy_conjoint_jshorts_atomic(from, to, count);94}9596static void pd_conjoint_jints_atomic(const jint* from, jint* to, size_t count) {97_Copy_conjoint_jints_atomic(from, to, count);98}99100static void pd_conjoint_jlongs_atomic(const jlong* from, jlong* to, size_t count) {101_Copy_conjoint_jlongs_atomic(from, to, count);102}103104static void pd_conjoint_oops_atomic(const oop* from, oop* to, size_t count) {105#ifdef _LP64106assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");107_Copy_conjoint_jlongs_atomic((const jlong*)from, (jlong*)to, count);108#else109assert(BytesPerInt == BytesPerOop, "jints and oops must be the same size");110_Copy_conjoint_jints_atomic((const jint*)from, (jint*)to, count);111#endif // _LP64112}113114static void pd_arrayof_conjoint_bytes(const HeapWord* from,115HeapWord* to,116size_t count) {117_Copy_arrayof_conjoint_bytes(from, to, count);118}119120static void pd_arrayof_conjoint_jshorts(const HeapWord* from,121HeapWord* to,122size_t count) {123_Copy_arrayof_conjoint_jshorts(from, to, count);124}125126static void pd_arrayof_conjoint_jints(const HeapWord* from,127HeapWord* to,128size_t count) {129_Copy_arrayof_conjoint_jints(from, to, count);130}131132static void pd_arrayof_conjoint_jlongs(const HeapWord* from,133HeapWord* to,134size_t count) {135_Copy_arrayof_conjoint_jlongs(from, to, count);136}137138static void pd_arrayof_conjoint_oops(const HeapWord* from,139HeapWord* to,140size_t count) {141#ifdef _LP64142assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");143_Copy_arrayof_conjoint_jlongs(from, to, count);144#else145assert(BytesPerInt == BytesPerOop, "jints and oops must be the same size");146_Copy_arrayof_conjoint_jints(from, to, count);147#endif // _LP64148}149150static void pd_fill_to_words(HeapWord* tohw, size_t count, juint value) {151#ifdef _LP64152julong* to = (julong*) tohw;153julong v = ((julong) value << 32) | value;154#else155juint* to = (juint*) tohw;156juint v = value;157#endif // _LP64158159while (count-- > 0) {160*to++ = v;161}162}163164static void pd_fill_to_aligned_words(HeapWord* tohw,165size_t count,166juint value) {167pd_fill_to_words(tohw, count, value);168}169170static void pd_fill_to_bytes(void* to, size_t count, jubyte value) {171memset(to, value, count);172}173174static void pd_zero_to_words(HeapWord* tohw, size_t count) {175pd_fill_to_words(tohw, count, 0);176}177178static void pd_zero_to_bytes(void* to, size_t count) {179memset(to, 0, count);180}181182#endif // CPU_ZERO_COPY_ZERO_HPP183184185