Wed, 27 Nov 2013 16:16:21 -0800
8029015: PPC64 (part 216): opto: trap based null and range checks
Summary: On PPC64 use tdi instruction that does a compare and raises SIGTRAP for NULL and range checks.
Reviewed-by: kvn
goetz@6458 | 1 | /* |
goetz@6458 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
goetz@6458 | 3 | * Copyright 2012, 2013 SAP AG. All rights reserved. |
goetz@6458 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
goetz@6458 | 5 | * |
goetz@6458 | 6 | * This code is free software; you can redistribute it and/or modify it |
goetz@6458 | 7 | * under the terms of the GNU General Public License version 2 only, as |
goetz@6458 | 8 | * published by the Free Software Foundation. |
goetz@6458 | 9 | * |
goetz@6458 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
goetz@6458 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
goetz@6458 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
goetz@6458 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
goetz@6458 | 14 | * accompanied this code). |
goetz@6458 | 15 | * |
goetz@6458 | 16 | * You should have received a copy of the GNU General Public License version |
goetz@6458 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
goetz@6458 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
goetz@6458 | 19 | * |
goetz@6458 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
goetz@6458 | 21 | * or visit www.oracle.com if you need additional information or have any |
goetz@6458 | 22 | * questions. |
goetz@6458 | 23 | * |
goetz@6458 | 24 | */ |
goetz@6458 | 25 | |
goetz@6458 | 26 | #ifndef CPU_PPC_VM_BYTES_PPC_HPP |
goetz@6458 | 27 | #define CPU_PPC_VM_BYTES_PPC_HPP |
goetz@6458 | 28 | |
goetz@6458 | 29 | #include "memory/allocation.hpp" |
goetz@6458 | 30 | |
goetz@6458 | 31 | class Bytes: AllStatic { |
goetz@6458 | 32 | public: |
goetz@6458 | 33 | // Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering |
goetz@6458 | 34 | // PowerPC needs to check for alignment. |
goetz@6458 | 35 | |
goetz@6458 | 36 | // can I count on address always being a pointer to an unsigned char? Yes |
goetz@6458 | 37 | |
goetz@6458 | 38 | // Returns true, if the byte ordering used by Java is different from the nativ byte ordering |
goetz@6458 | 39 | // of the underlying machine. For example, true for Intel x86, False, for Solaris on Sparc. |
goetz@6458 | 40 | static inline bool is_Java_byte_ordering_different() { return false; } |
goetz@6458 | 41 | |
goetz@6458 | 42 | // Thus, a swap between native and Java ordering is always a no-op: |
goetz@6458 | 43 | static inline u2 swap_u2(u2 x) { return x; } |
goetz@6458 | 44 | static inline u4 swap_u4(u4 x) { return x; } |
goetz@6458 | 45 | static inline u8 swap_u8(u8 x) { return x; } |
goetz@6458 | 46 | |
goetz@6458 | 47 | static inline u2 get_native_u2(address p) { |
goetz@6458 | 48 | return (intptr_t(p) & 1) == 0 |
goetz@6458 | 49 | ? *(u2*)p |
goetz@6458 | 50 | : ( u2(p[0]) << 8 ) |
goetz@6458 | 51 | | ( u2(p[1]) ); |
goetz@6458 | 52 | } |
goetz@6458 | 53 | |
goetz@6458 | 54 | static inline u4 get_native_u4(address p) { |
goetz@6458 | 55 | switch (intptr_t(p) & 3) { |
goetz@6458 | 56 | case 0: return *(u4*)p; |
goetz@6458 | 57 | |
goetz@6458 | 58 | case 2: return ( u4( ((u2*)p)[0] ) << 16 ) |
goetz@6458 | 59 | | ( u4( ((u2*)p)[1] ) ); |
goetz@6458 | 60 | |
goetz@6458 | 61 | default: return ( u4(p[0]) << 24 ) |
goetz@6458 | 62 | | ( u4(p[1]) << 16 ) |
goetz@6458 | 63 | | ( u4(p[2]) << 8 ) |
goetz@6458 | 64 | | u4(p[3]); |
goetz@6458 | 65 | } |
goetz@6458 | 66 | } |
goetz@6458 | 67 | |
goetz@6458 | 68 | static inline u8 get_native_u8(address p) { |
goetz@6458 | 69 | switch (intptr_t(p) & 7) { |
goetz@6458 | 70 | case 0: return *(u8*)p; |
goetz@6458 | 71 | |
goetz@6458 | 72 | case 4: return ( u8( ((u4*)p)[0] ) << 32 ) |
goetz@6458 | 73 | | ( u8( ((u4*)p)[1] ) ); |
goetz@6458 | 74 | |
goetz@6458 | 75 | case 2: return ( u8( ((u2*)p)[0] ) << 48 ) |
goetz@6458 | 76 | | ( u8( ((u2*)p)[1] ) << 32 ) |
goetz@6458 | 77 | | ( u8( ((u2*)p)[2] ) << 16 ) |
goetz@6458 | 78 | | ( u8( ((u2*)p)[3] ) ); |
goetz@6458 | 79 | |
goetz@6458 | 80 | default: return ( u8(p[0]) << 56 ) |
goetz@6458 | 81 | | ( u8(p[1]) << 48 ) |
goetz@6458 | 82 | | ( u8(p[2]) << 40 ) |
goetz@6458 | 83 | | ( u8(p[3]) << 32 ) |
goetz@6458 | 84 | | ( u8(p[4]) << 24 ) |
goetz@6458 | 85 | | ( u8(p[5]) << 16 ) |
goetz@6458 | 86 | | ( u8(p[6]) << 8 ) |
goetz@6458 | 87 | | u8(p[7]); |
goetz@6458 | 88 | } |
goetz@6458 | 89 | } |
goetz@6458 | 90 | |
goetz@6458 | 91 | |
goetz@6458 | 92 | |
goetz@6458 | 93 | static inline void put_native_u2(address p, u2 x) { |
goetz@6458 | 94 | if ( (intptr_t(p) & 1) == 0 ) { *(u2*)p = x; } |
goetz@6458 | 95 | else { |
goetz@6458 | 96 | p[0] = x >> 8; |
goetz@6458 | 97 | p[1] = x; |
goetz@6458 | 98 | } |
goetz@6458 | 99 | } |
goetz@6458 | 100 | |
goetz@6458 | 101 | static inline void put_native_u4(address p, u4 x) { |
goetz@6458 | 102 | switch ( intptr_t(p) & 3 ) { |
goetz@6458 | 103 | case 0: *(u4*)p = x; |
goetz@6458 | 104 | break; |
goetz@6458 | 105 | |
goetz@6458 | 106 | case 2: ((u2*)p)[0] = x >> 16; |
goetz@6458 | 107 | ((u2*)p)[1] = x; |
goetz@6458 | 108 | break; |
goetz@6458 | 109 | |
goetz@6458 | 110 | default: ((u1*)p)[0] = x >> 24; |
goetz@6458 | 111 | ((u1*)p)[1] = x >> 16; |
goetz@6458 | 112 | ((u1*)p)[2] = x >> 8; |
goetz@6458 | 113 | ((u1*)p)[3] = x; |
goetz@6458 | 114 | break; |
goetz@6458 | 115 | } |
goetz@6458 | 116 | } |
goetz@6458 | 117 | |
goetz@6458 | 118 | static inline void put_native_u8(address p, u8 x) { |
goetz@6458 | 119 | switch ( intptr_t(p) & 7 ) { |
goetz@6458 | 120 | case 0: *(u8*)p = x; |
goetz@6458 | 121 | break; |
goetz@6458 | 122 | |
goetz@6458 | 123 | case 4: ((u4*)p)[0] = x >> 32; |
goetz@6458 | 124 | ((u4*)p)[1] = x; |
goetz@6458 | 125 | break; |
goetz@6458 | 126 | |
goetz@6458 | 127 | case 2: ((u2*)p)[0] = x >> 48; |
goetz@6458 | 128 | ((u2*)p)[1] = x >> 32; |
goetz@6458 | 129 | ((u2*)p)[2] = x >> 16; |
goetz@6458 | 130 | ((u2*)p)[3] = x; |
goetz@6458 | 131 | break; |
goetz@6458 | 132 | |
goetz@6458 | 133 | default: ((u1*)p)[0] = x >> 56; |
goetz@6458 | 134 | ((u1*)p)[1] = x >> 48; |
goetz@6458 | 135 | ((u1*)p)[2] = x >> 40; |
goetz@6458 | 136 | ((u1*)p)[3] = x >> 32; |
goetz@6458 | 137 | ((u1*)p)[4] = x >> 24; |
goetz@6458 | 138 | ((u1*)p)[5] = x >> 16; |
goetz@6458 | 139 | ((u1*)p)[6] = x >> 8; |
goetz@6458 | 140 | ((u1*)p)[7] = x; |
goetz@6458 | 141 | } |
goetz@6458 | 142 | } |
goetz@6458 | 143 | |
goetz@6458 | 144 | |
goetz@6458 | 145 | // Efficient reading and writing of unaligned unsigned data in Java byte ordering (i.e. big-endian ordering) |
goetz@6458 | 146 | // (no byte-order reversal is needed since Power CPUs are big-endian oriented). |
goetz@6458 | 147 | static inline u2 get_Java_u2(address p) { return get_native_u2(p); } |
goetz@6458 | 148 | static inline u4 get_Java_u4(address p) { return get_native_u4(p); } |
goetz@6458 | 149 | static inline u8 get_Java_u8(address p) { return get_native_u8(p); } |
goetz@6458 | 150 | |
goetz@6458 | 151 | static inline void put_Java_u2(address p, u2 x) { put_native_u2(p, x); } |
goetz@6458 | 152 | static inline void put_Java_u4(address p, u4 x) { put_native_u4(p, x); } |
goetz@6458 | 153 | static inline void put_Java_u8(address p, u8 x) { put_native_u8(p, x); } |
goetz@6458 | 154 | }; |
goetz@6458 | 155 | |
goetz@6458 | 156 | #endif // CPU_PPC_VM_BYTES_PPC_HPP |