< prev index next >

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

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


1689         if (impl == null) {
1690             try {
1691                 @SuppressWarnings("deprecation")
1692                 Object tmp = Class.forName(implName).newInstance();
1693                 impl = tmp;
1694             } catch (Exception e) {
1695                 throw new Error("System property impl.prefix incorrect");
1696             }
1697         }
1698 
1699         return (InetAddressImpl) impl;
1700     }
1701 
1702     private void readObjectNoData (ObjectInputStream s) throws
1703                          IOException, ClassNotFoundException {
1704         if (getClass().getClassLoader() != null) {
1705             throw new SecurityException ("invalid address type");
1706         }
1707     }
1708 
1709     private static final long FIELDS_OFFSET;
1710     private static final jdk.internal.misc.Unsafe UNSAFE;
1711 
1712     static {
1713         try {
1714             jdk.internal.misc.Unsafe unsafe = jdk.internal.misc.Unsafe.getUnsafe();
1715             FIELDS_OFFSET = unsafe.objectFieldOffset(
1716                 InetAddress.class.getDeclaredField("holder")
1717             );
1718             UNSAFE = unsafe;
1719         } catch (ReflectiveOperationException e) {
1720             throw new Error(e);
1721         }
1722     }
1723 
1724     private void readObject (ObjectInputStream s) throws
1725                          IOException, ClassNotFoundException {
1726         if (getClass().getClassLoader() != null) {
1727             throw new SecurityException ("invalid address type");
1728         }
1729         GetField gf = s.readFields();
1730         String host = (String)gf.get("hostName", null);
1731         int address= gf.get("address", 0);
1732         int family= gf.get("family", 0);
1733         InetAddressHolder h = new InetAddressHolder(host, address, family);
1734         UNSAFE.putObject(this, FIELDS_OFFSET, h);
1735     }
1736 
1737     /* needed because the serializable fields no longer exist */
1738 
1739     /**
1740      * @serialField hostName String
1741      * @serialField address int
1742      * @serialField family int




1689         if (impl == null) {
1690             try {
1691                 @SuppressWarnings("deprecation")
1692                 Object tmp = Class.forName(implName).newInstance();
1693                 impl = tmp;
1694             } catch (Exception e) {
1695                 throw new Error("System property impl.prefix incorrect");
1696             }
1697         }
1698 
1699         return (InetAddressImpl) impl;
1700     }
1701 
1702     private void readObjectNoData (ObjectInputStream s) throws
1703                          IOException, ClassNotFoundException {
1704         if (getClass().getClassLoader() != null) {
1705             throw new SecurityException ("invalid address type");
1706         }
1707     }
1708 
1709     private static final jdk.internal.misc.Unsafe UNSAFE
1710             = jdk.internal.misc.Unsafe.getUnsafe();
1711     private static final long FIELDS_OFFSET
1712             = UNSAFE.objectFieldOffset(InetAddress.class, "holder");










1713 
1714     private void readObject (ObjectInputStream s) throws
1715                          IOException, ClassNotFoundException {
1716         if (getClass().getClassLoader() != null) {
1717             throw new SecurityException ("invalid address type");
1718         }
1719         GetField gf = s.readFields();
1720         String host = (String)gf.get("hostName", null);
1721         int address= gf.get("address", 0);
1722         int family= gf.get("family", 0);
1723         InetAddressHolder h = new InetAddressHolder(host, address, family);
1724         UNSAFE.putObject(this, FIELDS_OFFSET, h);
1725     }
1726 
1727     /* needed because the serializable fields no longer exist */
1728 
1729     /**
1730      * @serialField hostName String
1731      * @serialField address int
1732      * @serialField family int


< prev index next >