src/java.base/share/classes/java/net/InetSocketAddress.java

Print this page
rev 12972 : 8140606: Update library code to use internal Unsafe
Reviewed-by: duke


 286 
 287         // Check that our invariants are satisfied
 288         checkPort(oisPort);
 289         if (oisHostname == null && oisAddr == null)
 290             throw new InvalidObjectException("hostname and addr " +
 291                                              "can't both be null");
 292 
 293         InetSocketAddressHolder h = new InetSocketAddressHolder(oisHostname,
 294                                                                 oisAddr,
 295                                                                 oisPort);
 296         UNSAFE.putObject(this, FIELDS_OFFSET, h);
 297     }
 298 
 299     private void readObjectNoData()
 300         throws ObjectStreamException
 301     {
 302         throw new InvalidObjectException("Stream data required");
 303     }
 304 
 305     private static final long FIELDS_OFFSET;
 306     private static final sun.misc.Unsafe UNSAFE;
 307     static {
 308         try {
 309             sun.misc.Unsafe unsafe = sun.misc.Unsafe.getUnsafe();
 310             FIELDS_OFFSET = unsafe.objectFieldOffset(
 311                     InetSocketAddress.class.getDeclaredField("holder"));
 312             UNSAFE = unsafe;
 313         } catch (ReflectiveOperationException e) {
 314             throw new Error(e);
 315         }
 316     }
 317 
 318     /**
 319      * Gets the port number.
 320      *
 321      * @return the port number.
 322      */
 323     public final int getPort() {
 324         return holder.getPort();
 325     }
 326 
 327     /**
 328      *
 329      * Gets the {@code InetAddress}.




 286 
 287         // Check that our invariants are satisfied
 288         checkPort(oisPort);
 289         if (oisHostname == null && oisAddr == null)
 290             throw new InvalidObjectException("hostname and addr " +
 291                                              "can't both be null");
 292 
 293         InetSocketAddressHolder h = new InetSocketAddressHolder(oisHostname,
 294                                                                 oisAddr,
 295                                                                 oisPort);
 296         UNSAFE.putObject(this, FIELDS_OFFSET, h);
 297     }
 298 
 299     private void readObjectNoData()
 300         throws ObjectStreamException
 301     {
 302         throw new InvalidObjectException("Stream data required");
 303     }
 304 
 305     private static final long FIELDS_OFFSET;
 306     private static final jdk.internal.misc.Unsafe UNSAFE;
 307     static {
 308         try {
 309             jdk.internal.misc.Unsafe unsafe = jdk.internal.misc.Unsafe.getUnsafe();
 310             FIELDS_OFFSET = unsafe.objectFieldOffset(
 311                     InetSocketAddress.class.getDeclaredField("holder"));
 312             UNSAFE = unsafe;
 313         } catch (ReflectiveOperationException e) {
 314             throw new Error(e);
 315         }
 316     }
 317 
 318     /**
 319      * Gets the port number.
 320      *
 321      * @return the port number.
 322      */
 323     public final int getPort() {
 324         return holder.getPort();
 325     }
 326 
 327     /**
 328      *
 329      * Gets the {@code InetAddress}.