src/java.base/share/classes/java/lang/Byte.java
changeset 52626 991fe09c698c
parent 47216 71c04702a3d5
child 54952 a978d86ac389
equal deleted inserted replaced
52625:5e23b9a66fe6 52626:991fe09c698c
    24  */
    24  */
    25 
    25 
    26 package java.lang;
    26 package java.lang;
    27 
    27 
    28 import jdk.internal.HotSpotIntrinsicCandidate;
    28 import jdk.internal.HotSpotIntrinsicCandidate;
       
    29 import jdk.internal.misc.VM;
    29 
    30 
    30 /**
    31 /**
    31  *
    32  *
    32  * The {@code Byte} class wraps a value of primitive type {@code byte}
    33  * The {@code Byte} class wraps a value of primitive type {@code byte}
    33  * in an object.  An object of type {@code Byte} contains a single
    34  * in an object.  An object of type {@code Byte} contains a single
    75     public static String toString(byte b) {
    76     public static String toString(byte b) {
    76         return Integer.toString((int)b, 10);
    77         return Integer.toString((int)b, 10);
    77     }
    78     }
    78 
    79 
    79     private static class ByteCache {
    80     private static class ByteCache {
    80         private ByteCache(){}
    81         private ByteCache() {}
    81 
    82 
    82         static final Byte cache[] = new Byte[-(-128) + 127 + 1];
    83         static final Byte[] cache;
       
    84         static Byte[] archivedCache;
    83 
    85 
    84         static {
    86         static {
    85             for(int i = 0; i < cache.length; i++)
    87             final int size = -(-128) + 127 + 1;
    86                 cache[i] = new Byte((byte)(i - 128));
    88 
       
    89             // Load and use the archived cache if it exists
       
    90             VM.initializeFromArchive(ByteCache.class);
       
    91             if (archivedCache == null || archivedCache.length != size) {
       
    92                 Byte[] c = new Byte[size];
       
    93                 byte value = (byte)-128;
       
    94                 for(int i = 0; i < size; i++) {
       
    95                     c[i] = new Byte(value++);
       
    96                 }
       
    97                 archivedCache = c;
       
    98             }
       
    99             cache = archivedCache;
    87         }
   100         }
    88     }
   101     }
    89 
   102 
    90     /**
   103     /**
    91      * Returns a {@code Byte} instance representing the specified
   104      * Returns a {@code Byte} instance representing the specified