Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/zero/vm/bytes_zero.hpp
32285 views
/*1* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.2* Copyright 2007, 2008, 2009 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_VM_BYTES_ZERO_HPP26#define CPU_ZERO_VM_BYTES_ZERO_HPP2728#include "memory/allocation.hpp"2930typedef union unaligned {31u4 u;32u2 us;33u8 ul;34} __attribute__((packed)) unaligned;3536class Bytes: AllStatic {37public:38// Returns true if the byte ordering used by Java is different39// from the native byte ordering of the underlying machine.40static inline bool is_Java_byte_ordering_different() {41#ifdef VM_LITTLE_ENDIAN42return true;43#else44return false;45#endif46}4748// Efficient reading and writing of unaligned unsigned data in49// platform-specific byte ordering.50static inline u2 get_native_u2(address p){51unaligned *up = (unaligned *) p;52return up->us;53}5455static inline u4 get_native_u4(address p) {56unaligned *up = (unaligned *) p;57return up->u;58}5960static inline u8 get_native_u8(address p) {61unaligned *up = (unaligned *) p;62return up->ul;63}6465static inline void put_native_u2(address p, u2 x) {66unaligned *up = (unaligned *) p;67up->us = x;68}6970static inline void put_native_u4(address p, u4 x) {71unaligned *up = (unaligned *) p;72up->u = x;73}7475static inline void put_native_u8(address p, u8 x) {76unaligned *up = (unaligned *) p;77up->ul = x;78}7980// Efficient reading and writing of unaligned unsigned data in Java81// byte ordering (i.e. big-endian ordering).82#ifdef VM_LITTLE_ENDIAN83// Byte-order reversal is needed84static inline u2 get_Java_u2(address p) {85return (u2(p[0]) << 8) |86(u2(p[1]) );87}88static inline u4 get_Java_u4(address p) {89return (u4(p[0]) << 24) |90(u4(p[1]) << 16) |91(u4(p[2]) << 8) |92(u4(p[3]) );93}94static inline u8 get_Java_u8(address p) {95u4 hi, lo;96hi = (u4(p[0]) << 24) |97(u4(p[1]) << 16) |98(u4(p[2]) << 8) |99(u4(p[3]) );100lo = (u4(p[4]) << 24) |101(u4(p[5]) << 16) |102(u4(p[6]) << 8) |103(u4(p[7]) );104return u8(lo) | (u8(hi) << 32);105}106107static inline void put_Java_u2(address p, u2 x) {108p[0] = x >> 8;109p[1] = x;110}111static inline void put_Java_u4(address p, u4 x) {112p[0] = x >> 24;113p[1] = x >> 16;114p[2] = x >> 8;115p[3] = x;116}117static inline void put_Java_u8(address p, u8 x) {118u4 hi, lo;119lo = x;120hi = x >> 32;121p[0] = hi >> 24;122p[1] = hi >> 16;123p[2] = hi >> 8;124p[3] = hi;125p[4] = lo >> 24;126p[5] = lo >> 16;127p[6] = lo >> 8;128p[7] = lo;129}130131// Efficient swapping of byte ordering132static inline u2 swap_u2(u2 x);133static inline u4 swap_u4(u4 x);134static inline u8 swap_u8(u8 x);135#else136// No byte-order reversal is needed137static inline u2 get_Java_u2(address p) {138return get_native_u2(p);139}140static inline u4 get_Java_u4(address p) {141return get_native_u4(p);142}143static inline u8 get_Java_u8(address p) {144return get_native_u8(p);145}146147static inline void put_Java_u2(address p, u2 x) {148put_native_u2(p, x);149}150static inline void put_Java_u4(address p, u4 x) {151put_native_u4(p, x);152}153static inline void put_Java_u8(address p, u8 x) {154put_native_u8(p, x);155}156157// No byte-order reversal is needed158static inline u2 swap_u2(u2 x) { return x; }159static inline u4 swap_u4(u4 x) { return x; }160static inline u8 swap_u8(u8 x) { return x; }161#endif // VM_LITTLE_ENDIAN162};163164#ifdef VM_LITTLE_ENDIAN165// The following header contains the implementations of swap_u2,166// swap_u4, and swap_u8167#ifdef TARGET_OS_ARCH_linux_zero168# include "bytes_linux_zero.inline.hpp"169#endif170#ifdef TARGET_OS_ARCH_bsd_zero171# include "bytes_bsd_zero.inline.hpp"172#endif173174#endif // VM_LITTLE_ENDIAN175176#endif // CPU_ZERO_VM_BYTES_ZERO_HPP177178179