annotate src/cpu/zero/vm/bytes_zero.hpp @ 5819:39f4affc6564

8143245: Zero build requires disabled warnings 8022956: Clang: enable return type warnings on BSD Summary: Based on work of Severin Gehwolf <sgehwolf@redhat.com> & Christian Thalinger <cthalinger@twitter.com> with additions for 7-only cases Reviewed-by: dholmes, coleenp, sla
author andrew
date Tue, 13 Feb 2018 06:42:27 +0000
parents f95d63e2154a
children
rev   line source
never@1010 1 /*
stefank@1879 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
never@1010 3 * Copyright 2007, 2008, 2009 Red Hat, Inc.
never@1010 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
never@1010 5 *
never@1010 6 * This code is free software; you can redistribute it and/or modify it
never@1010 7 * under the terms of the GNU General Public License version 2 only, as
never@1010 8 * published by the Free Software Foundation.
never@1010 9 *
never@1010 10 * This code is distributed in the hope that it will be useful, but WITHOUT
never@1010 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
never@1010 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
never@1010 13 * version 2 for more details (a copy is included in the LICENSE file that
never@1010 14 * accompanied this code).
never@1010 15 *
never@1010 16 * You should have received a copy of the GNU General Public License version
never@1010 17 * 2 along with this work; if not, write to the Free Software Foundation,
never@1010 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
never@1010 19 *
trims@1472 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 21 * or visit www.oracle.com if you need additional information or have any
trims@1472 22 * questions.
never@1010 23 *
never@1010 24 */
never@1010 25
stefank@1879 26 #ifndef CPU_ZERO_VM_BYTES_ZERO_HPP
stefank@1879 27 #define CPU_ZERO_VM_BYTES_ZERO_HPP
stefank@1879 28
stefank@1879 29 #include "memory/allocation.hpp"
stefank@1879 30
never@1010 31 typedef union unaligned {
never@1010 32 u4 u;
never@1010 33 u2 us;
never@1010 34 u8 ul;
never@1010 35 } __attribute__((packed)) unaligned;
never@1010 36
never@1010 37 class Bytes: AllStatic {
never@1010 38 public:
never@1010 39 // Returns true if the byte ordering used by Java is different
never@1010 40 // from the native byte ordering of the underlying machine.
never@1010 41 static inline bool is_Java_byte_ordering_different() {
never@1010 42 #ifdef VM_LITTLE_ENDIAN
never@1010 43 return true;
never@1010 44 #else
never@1010 45 return false;
never@1010 46 #endif
never@1010 47 }
never@1010 48
never@1010 49 // Efficient reading and writing of unaligned unsigned data in
never@1010 50 // platform-specific byte ordering.
never@1010 51 static inline u2 get_native_u2(address p){
never@1010 52 unaligned *up = (unaligned *) p;
never@1010 53 return up->us;
never@1010 54 }
never@1010 55
never@1010 56 static inline u4 get_native_u4(address p) {
never@1010 57 unaligned *up = (unaligned *) p;
never@1010 58 return up->u;
never@1010 59 }
never@1010 60
never@1010 61 static inline u8 get_native_u8(address p) {
never@1010 62 unaligned *up = (unaligned *) p;
never@1010 63 return up->ul;
never@1010 64 }
never@1010 65
never@1010 66 static inline void put_native_u2(address p, u2 x) {
never@1010 67 unaligned *up = (unaligned *) p;
never@1010 68 up->us = x;
never@1010 69 }
never@1010 70
never@1010 71 static inline void put_native_u4(address p, u4 x) {
never@1010 72 unaligned *up = (unaligned *) p;
never@1010 73 up->u = x;
never@1010 74 }
never@1010 75
never@1010 76 static inline void put_native_u8(address p, u8 x) {
never@1010 77 unaligned *up = (unaligned *) p;
never@1010 78 up->ul = x;
never@1010 79 }
never@1010 80
never@1010 81 // Efficient reading and writing of unaligned unsigned data in Java
never@1010 82 // byte ordering (i.e. big-endian ordering).
never@1010 83 #ifdef VM_LITTLE_ENDIAN
never@1010 84 // Byte-order reversal is needed
never@1010 85 static inline u2 get_Java_u2(address p) {
never@1010 86 return (u2(p[0]) << 8) |
never@1010 87 (u2(p[1]) );
never@1010 88 }
never@1010 89 static inline u4 get_Java_u4(address p) {
never@1010 90 return (u4(p[0]) << 24) |
never@1010 91 (u4(p[1]) << 16) |
never@1010 92 (u4(p[2]) << 8) |
never@1010 93 (u4(p[3]) );
never@1010 94 }
never@1010 95 static inline u8 get_Java_u8(address p) {
never@1010 96 u4 hi, lo;
never@1010 97 hi = (u4(p[0]) << 24) |
never@1010 98 (u4(p[1]) << 16) |
never@1010 99 (u4(p[2]) << 8) |
never@1010 100 (u4(p[3]) );
never@1010 101 lo = (u4(p[4]) << 24) |
never@1010 102 (u4(p[5]) << 16) |
never@1010 103 (u4(p[6]) << 8) |
never@1010 104 (u4(p[7]) );
never@1010 105 return u8(lo) | (u8(hi) << 32);
never@1010 106 }
never@1010 107
never@1010 108 static inline void put_Java_u2(address p, u2 x) {
never@1010 109 p[0] = x >> 8;
never@1010 110 p[1] = x;
never@1010 111 }
never@1010 112 static inline void put_Java_u4(address p, u4 x) {
never@1010 113 p[0] = x >> 24;
never@1010 114 p[1] = x >> 16;
never@1010 115 p[2] = x >> 8;
never@1010 116 p[3] = x;
never@1010 117 }
never@1010 118 static inline void put_Java_u8(address p, u8 x) {
never@1010 119 u4 hi, lo;
never@1010 120 lo = x;
never@1010 121 hi = x >> 32;
never@1010 122 p[0] = hi >> 24;
never@1010 123 p[1] = hi >> 16;
never@1010 124 p[2] = hi >> 8;
never@1010 125 p[3] = hi;
never@1010 126 p[4] = lo >> 24;
never@1010 127 p[5] = lo >> 16;
never@1010 128 p[6] = lo >> 8;
never@1010 129 p[7] = lo;
never@1010 130 }
never@1010 131
never@1010 132 // Efficient swapping of byte ordering
never@1010 133 static inline u2 swap_u2(u2 x);
never@1010 134 static inline u4 swap_u4(u4 x);
never@1010 135 static inline u8 swap_u8(u8 x);
never@1010 136 #else
never@1010 137 // No byte-order reversal is needed
never@1010 138 static inline u2 get_Java_u2(address p) {
never@1010 139 return get_native_u2(p);
never@1010 140 }
never@1010 141 static inline u4 get_Java_u4(address p) {
never@1010 142 return get_native_u4(p);
never@1010 143 }
never@1010 144 static inline u8 get_Java_u8(address p) {
never@1010 145 return get_native_u8(p);
never@1010 146 }
never@1010 147
never@1010 148 static inline void put_Java_u2(address p, u2 x) {
never@1010 149 put_native_u2(p, x);
never@1010 150 }
never@1010 151 static inline void put_Java_u4(address p, u4 x) {
never@1010 152 put_native_u4(p, x);
never@1010 153 }
never@1010 154 static inline void put_Java_u8(address p, u8 x) {
never@1010 155 put_native_u8(p, x);
never@1010 156 }
never@1010 157
never@1010 158 // No byte-order reversal is needed
never@1010 159 static inline u2 swap_u2(u2 x) { return x; }
never@1010 160 static inline u4 swap_u4(u4 x) { return x; }
never@1010 161 static inline u8 swap_u8(u8 x) { return x; }
never@1010 162 #endif // VM_LITTLE_ENDIAN
never@1010 163 };
never@1010 164
never@1010 165 #ifdef VM_LITTLE_ENDIAN
never@1010 166 // The following header contains the implementations of swap_u2,
never@1010 167 // swap_u4, and swap_u8
stefank@1879 168 #ifdef TARGET_OS_ARCH_linux_zero
stefank@1879 169 # include "bytes_linux_zero.inline.hpp"
stefank@1879 170 #endif
never@2796 171 #ifdef TARGET_OS_ARCH_bsd_zero
never@2796 172 # include "bytes_bsd_zero.inline.hpp"
never@2796 173 #endif
stefank@1879 174
never@1010 175 #endif // VM_LITTLE_ENDIAN
stefank@1879 176
stefank@1879 177 #endif // CPU_ZERO_VM_BYTES_ZERO_HPP