< prev index next >

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

Print this page
rev 17358 : 8182487: Add Unsafe.objectFieldOffset(Class, String)
Reviewed-by: dsimms


 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}.
 330      *
 331      * @return the InetAdress or {@code null} if it is unresolved.
 332      */
 333     public final InetAddress getAddress() {
 334         return holder.getAddress();
 335     }




 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         jdk.internal.misc.Unsafe unsafe = jdk.internal.misc.Unsafe.getUnsafe();
 309         FIELDS_OFFSET = unsafe.objectFieldOffset(InetSocketAddress.class, "holder");

 310         UNSAFE = unsafe;



 311     }
 312 
 313     /**
 314      * Gets the port number.
 315      *
 316      * @return the port number.
 317      */
 318     public final int getPort() {
 319         return holder.getPort();
 320     }
 321 
 322     /**
 323      *
 324      * Gets the {@code InetAddress}.
 325      *
 326      * @return the InetAdress or {@code null} if it is unresolved.
 327      */
 328     public final InetAddress getAddress() {
 329         return holder.getAddress();
 330     }


< prev index next >