hotspot/src/cpu/sparc/vm/bytes_sparc.hpp
author mikael
Fri, 26 May 2017 13:47:33 -0700
changeset 46504 38048d4d20e7
parent 7397 5b173b4ca846
permissions -rw-r--r--
8180032: Unaligned pointer dereference in ClassFileParser Reviewed-by: dholmes, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef CPU_SPARC_VM_BYTES_SPARC_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define CPU_SPARC_VM_BYTES_SPARC_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
class Bytes: AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  // Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  // Sparc needs to check for alignment.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  // can I count on address always being a pointer to an unsigned char? Yes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  // Thus, a swap between native and Java ordering is always a no-op:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  static inline u2   swap_u2(u2 x)  { return x; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  static inline u4   swap_u4(u4 x)  { return x; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  static inline u8   swap_u8(u8 x)  { return x; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  static inline u2   get_native_u2(address p){
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    return (intptr_t(p) & 1) == 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
             ?   *(u2*)p
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
             :   ( u2(p[0]) << 8 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
               | ( u2(p[1])      );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  static inline u4   get_native_u4(address p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    switch (intptr_t(p) & 3) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
     case 0:  return *(u4*)p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
     case 2:  return (  u4( ((u2*)p)[0] ) << 16  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
                   | (  u4( ((u2*)p)[1] )                  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    default:  return ( u4(p[0]) << 24 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
                   | ( u4(p[1]) << 16 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
                   | ( u4(p[2]) <<  8 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
                   |   u4(p[3]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  static inline u8   get_native_u8(address p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    switch (intptr_t(p) & 7) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      case 0:  return *(u8*)p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      case 4:  return (  u8( ((u4*)p)[0] ) << 32  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
                    | (  u8( ((u4*)p)[1] )        );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
      case 2:  return (  u8( ((u2*)p)[0] ) << 48  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
                    | (  u8( ((u2*)p)[1] ) << 32  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
                    | (  u8( ((u2*)p)[2] ) << 16  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
                    | (  u8( ((u2*)p)[3] )        );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
     default:  return ( u8(p[0]) << 56 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
                    | ( u8(p[1]) << 48 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
                    | ( u8(p[2]) << 40 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
                    | ( u8(p[3]) << 32 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
                    | ( u8(p[4]) << 24 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
                    | ( u8(p[5]) << 16 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
                    | ( u8(p[6]) <<  8 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
                    |   u8(p[7]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  static inline void put_native_u2(address p, u2 x)   {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    if ( (intptr_t(p) & 1) == 0 )  *(u2*)p = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      p[0] = x >> 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      p[1] = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  static inline void put_native_u4(address p, u4 x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    switch ( intptr_t(p) & 3 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    case 0:  *(u4*)p = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
              break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    case 2:  ((u2*)p)[0] = x >> 16;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
             ((u2*)p)[1] = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
             break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    default: ((u1*)p)[0] = x >> 24;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
             ((u1*)p)[1] = x >> 16;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
             ((u1*)p)[2] = x >>  8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
             ((u1*)p)[3] = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
             break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  static inline void put_native_u8(address p, u8 x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    switch ( intptr_t(p) & 7 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    case 0:  *(u8*)p = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
             break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    case 4:  ((u4*)p)[0] = x >> 32;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
             ((u4*)p)[1] = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
             break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    case 2:  ((u2*)p)[0] = x >> 48;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
             ((u2*)p)[1] = x >> 32;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
             ((u2*)p)[2] = x >> 16;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
             ((u2*)p)[3] = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
             break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    default: ((u1*)p)[0] = x >> 56;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
             ((u1*)p)[1] = x >> 48;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
             ((u1*)p)[2] = x >> 40;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
             ((u1*)p)[3] = x >> 32;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
             ((u1*)p)[4] = x >> 24;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
             ((u1*)p)[5] = x >> 16;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
             ((u1*)p)[6] = x >>  8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
             ((u1*)p)[7] = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  // Efficient reading and writing of unaligned unsigned data in Java byte ordering (i.e. big-endian ordering)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // (no byte-order reversal is needed since SPARC CPUs are big-endian oriented)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  static inline u2   get_Java_u2(address p) { return get_native_u2(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  static inline u4   get_Java_u4(address p) { return get_native_u4(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  static inline u8   get_Java_u8(address p) { return get_native_u8(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  static inline void put_Java_u2(address p, u2 x)     { put_native_u2(p, x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  static inline void put_Java_u4(address p, u4 x)     { put_native_u4(p, x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  static inline void put_Java_u8(address p, u8 x)     { put_native_u8(p, x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
//Reconciliation History
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
// 1.7 98/02/24 10:18:41 bytes_i486.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
// 1.10 98/04/08 18:47:57 bytes_i486.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
// 1.13 98/07/15 17:10:03 bytes_i486.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
// 1.14 98/08/13 10:38:23 bytes_i486.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
// 1.15 98/10/05 16:30:21 bytes_i486.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
// 1.17 99/06/22 16:37:35 bytes_i486.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
//End
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   159
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   160
#endif // CPU_SPARC_VM_BYTES_SPARC_HPP