diff options
-rw-r--r-- | openjdk/allsources.lst | 1 | ||||
-rw-r--r-- | openjdk/java/io/ObjectStreamClass.java | 63 | ||||
-rw-r--r-- | openjdk/java/lang/ClassLoader.java | 11 | ||||
-rw-r--r-- | openjdk/java/lang/ClassLoaderHelper.java | 12 | ||||
-rw-r--r-- | openjdk/java/lang/ProcessImpl.java | 5 | ||||
-rw-r--r-- | openjdk/java/lang/invoke/MethodHandles.java | 18 | ||||
-rw-r--r-- | openjdk/java/net/TwoStacksPlainDatagramSocketImpl.java | 7 | ||||
-rw-r--r-- | openjdk/java/net/TwoStacksPlainSocketImpl.java | 14 | ||||
-rw-r--r-- | openjdk/sun/management/ManagementFactoryHelper.java | 6 | ||||
-rw-r--r-- | openjdk/sun/nio/ch/DatagramChannelImpl.java | 9 |
10 files changed, 102 insertions, 44 deletions
diff --git a/openjdk/allsources.lst b/openjdk/allsources.lst index b7305755..e0cdd0f2 100644 --- a/openjdk/allsources.lst +++ b/openjdk/allsources.lst @@ -80,6 +80,7 @@ java/io/ObjectStreamField.java java/io/RandomAccessFile.java java/lang/Class.java java/lang/ClassLoader.java +java/lang/ClassLoaderHelper.java java/lang/Enum.java java/lang/invoke/AdapterMethodHandle.java java/lang/invoke/BoundMethodHandle.java diff --git a/openjdk/java/io/ObjectStreamClass.java b/openjdk/java/io/ObjectStreamClass.java index 5a77f3dc..7cca3552 100644 --- a/openjdk/java/io/ObjectStreamClass.java +++ b/openjdk/java/io/ObjectStreamClass.java @@ -124,14 +124,39 @@ public class ObjectStreamClass implements Serializable { */ private boolean hasBlockExternalData = true; + /** + * Contains information about InvalidClassException instances to be thrown + * when attempting operations on an invalid class. Note that instances of + * this class are immutable and are potentially shared among + * ObjectStreamClass instances. + */ + private static class ExceptionInfo { + private final String className; + private final String message; + + ExceptionInfo(String cn, String msg) { + className = cn; + message = msg; + } + + /** + * Returns (does not throw) an InvalidClassException instance created + * from the information in this object, suitable for being thrown by + * the caller. + */ + InvalidClassException newInvalidClassException() { + return new InvalidClassException(className, message); + } + } + /** exception (if any) thrown while attempting to resolve class */ private ClassNotFoundException resolveEx; /** exception (if any) to throw if non-enum deserialization attempted */ - private InvalidClassException deserializeEx; + private ExceptionInfo deserializeEx; /** exception (if any) to throw if non-enum serialization attempted */ - private InvalidClassException serializeEx; + private ExceptionInfo serializeEx; /** exception (if any) to throw if default serialization attempted */ - private InvalidClassException defaultSerializeEx; + private ExceptionInfo defaultSerializeEx; /** serializable fields */ private ObjectStreamField[] fields; @@ -449,7 +474,8 @@ public class ObjectStreamClass implements Serializable { fields = getSerialFields(cl); computeFieldOffsets(); } catch (InvalidClassException e) { - serializeEx = deserializeEx = e; + serializeEx = deserializeEx = + new ExceptionInfo(e.classname, e.getMessage()); fields = NO_FIELDS; } @@ -488,15 +514,14 @@ public class ObjectStreamClass implements Serializable { if (deserializeEx == null) { if (isEnum) { - deserializeEx = new InvalidClassException(name, "enum type"); + deserializeEx = new ExceptionInfo(name, "enum type"); } else if (cons == null) { - deserializeEx = new InvalidClassException( - name, "no valid constructor"); + deserializeEx = new ExceptionInfo(name, "no valid constructor"); } } for (int i = 0; i < fields.length; i++) { if (fields[i].getField() == null) { - defaultSerializeEx = new InvalidClassException( + defaultSerializeEx = new ExceptionInfo( name, "unmatched serializable field(s) declared"); } } @@ -606,8 +631,8 @@ public class ObjectStreamClass implements Serializable { (externalizable != localDesc.externalizable) || !(serializable || externalizable)) { - deserializeEx = new InvalidClassException(localDesc.name, - "class invalid for deserialization"); + deserializeEx = new ExceptionInfo( + localDesc.name, "class invalid for deserialization"); } } @@ -732,11 +757,7 @@ public class ObjectStreamClass implements Serializable { */ void checkDeserialize() throws InvalidClassException { if (deserializeEx != null) { - InvalidClassException ice = - new InvalidClassException(deserializeEx.classname, - deserializeEx.getMessage()); - ice.initCause(deserializeEx); - throw ice; + throw deserializeEx.newInvalidClassException(); } } @@ -747,11 +768,7 @@ public class ObjectStreamClass implements Serializable { */ void checkSerialize() throws InvalidClassException { if (serializeEx != null) { - InvalidClassException ice = - new InvalidClassException(serializeEx.classname, - serializeEx.getMessage()); - ice.initCause(serializeEx); - throw ice; + throw serializeEx.newInvalidClassException(); } } @@ -764,11 +781,7 @@ public class ObjectStreamClass implements Serializable { */ void checkDefaultSerialize() throws InvalidClassException { if (defaultSerializeEx != null) { - InvalidClassException ice = - new InvalidClassException(defaultSerializeEx.classname, - defaultSerializeEx.getMessage()); - ice.initCause(defaultSerializeEx); - throw ice; + throw defaultSerializeEx.newInvalidClassException(); } } diff --git a/openjdk/java/lang/ClassLoader.java b/openjdk/java/lang/ClassLoader.java index ffd944f3..d759584c 100644 --- a/openjdk/java/lang/ClassLoader.java +++ b/openjdk/java/lang/ClassLoader.java @@ -1903,6 +1903,17 @@ public abstract class ClassLoader { } private static boolean loadLibrary0(Class fromClass, final File file) { + if (loadLibrary1(fromClass, file)) { + return true; + } + final File libfile = ClassLoaderHelper.mapAlternativeName(file); + if (libfile != null && loadLibrary1(fromClass, libfile)) { + return true; + } + return false; + } + + private static boolean loadLibrary1(Class fromClass, final File file) { boolean exists = AccessController.doPrivileged( new PrivilegedAction<Object>() { public Object run() { diff --git a/openjdk/java/lang/ClassLoaderHelper.java b/openjdk/java/lang/ClassLoaderHelper.java index 47438130..c37c47e8 100644 --- a/openjdk/java/lang/ClassLoaderHelper.java +++ b/openjdk/java/lang/ClassLoaderHelper.java @@ -37,11 +37,15 @@ class ClassLoaderHelper { * For mac, this replaces the final .dylib suffix with .jnilib */ static File mapAlternativeName(File lib) { - String name = lib.toString(); - int index = name.toLowerCase().lastIndexOf(".dylib"); - if (index < 0) { + if (ikvm.internal.Util.MACOSX) { + String name = lib.toString(); + int index = name.toLowerCase().lastIndexOf(".dylib"); + if (index < 0) { + return null; + } + return new File(name.substring(0, index) + ".jnilib"); + } else { return null; } - return new File(name.substring(0, index) + ".jnilib"); } } diff --git a/openjdk/java/lang/ProcessImpl.java b/openjdk/java/lang/ProcessImpl.java index 0b5a4e9a..9147b345 100644 --- a/openjdk/java/lang/ProcessImpl.java +++ b/openjdk/java/lang/ProcessImpl.java @@ -78,10 +78,11 @@ final class ProcessImpl extends Process { throws IOException { if (append) { + String path = f.getPath(); SecurityManager sm = System.getSecurityManager(); if (sm != null) - sm.checkWrite(f.getPath()); - final FileDescriptor fd = openForAtomicAppend(f.getPath()); + sm.checkWrite(path); + final FileDescriptor fd = openForAtomicAppend(path); return AccessController.doPrivileged( new PrivilegedAction<FileOutputStream>() { public FileOutputStream run() { diff --git a/openjdk/java/lang/invoke/MethodHandles.java b/openjdk/java/lang/invoke/MethodHandles.java index 36d9e219..632bb3e9 100644 --- a/openjdk/java/lang/invoke/MethodHandles.java +++ b/openjdk/java/lang/invoke/MethodHandles.java @@ -951,10 +951,11 @@ return mh1; public MethodHandle unreflect(Method m) throws IllegalAccessException { MemberName method = new MemberName(m); assert(method.isMethod()); - if (!m.isAccessible()) checkMethod(method.getDeclaringClass(), method, method.isStatic()); + if (m.isAccessible()) + return MethodHandleImpl.findMethod(method, true, /*no lookupClass*/ null); + checkMethod(method.getDeclaringClass(), method, method.isStatic()); MethodHandle mh = MethodHandleImpl.findMethod(method, true, lookupClassOrNull()); - if (!m.isAccessible()) mh = restrictProtectedReceiver(method, mh); - return mh; + return restrictProtectedReceiver(method, mh); } /** @@ -1012,8 +1013,13 @@ return mh1; public MethodHandle unreflectConstructor(Constructor c) throws IllegalAccessException { MemberName ctor = new MemberName(c); assert(ctor.isConstructor()); - if (!c.isAccessible()) checkAccess(c.getDeclaringClass(), ctor); - MethodHandle rawCtor = MethodHandleImpl.findMethod(ctor, false, lookupClassOrNull()); + MethodHandle rawCtor; + if (c.isAccessible()) { + rawCtor = MethodHandleImpl.findMethod(ctor, false, /*no lookupClass*/ null); + } else { + checkAccess(c.getDeclaringClass(), ctor); + rawCtor = MethodHandleImpl.findMethod(ctor, false, lookupClassOrNull()); + } MethodHandle allocator = MethodHandleImpl.makeAllocator(rawCtor); return fixVarargs(allocator, rawCtor); } @@ -1228,7 +1234,7 @@ return mh1; ? "expected a static field" : "expected a non-static field", this); if (trusted) - return MethodHandleImpl.accessField(field, isSetter, lookupClassOrNull()); + return MethodHandleImpl.accessField(field, isSetter, /*no lookupClass*/ null); checkAccess(refc, field); MethodHandle mh = MethodHandleImpl.accessField(field, isSetter, lookupClassOrNull()); return restrictProtectedReceiver(field, mh); diff --git a/openjdk/java/net/TwoStacksPlainDatagramSocketImpl.java b/openjdk/java/net/TwoStacksPlainDatagramSocketImpl.java index e606c758..2ca04f17 100644 --- a/openjdk/java/net/TwoStacksPlainDatagramSocketImpl.java +++ b/openjdk/java/net/TwoStacksPlainDatagramSocketImpl.java @@ -65,7 +65,12 @@ class TwoStacksPlainDatagramSocketImpl extends AbstractPlainDatagramSocketImpl protected synchronized void create() throws SocketException { fd1 = new FileDescriptor(); - super.create(); + try { + super.create(); + } catch (SocketException e) { + fd1 = null; + throw e; + } } protected synchronized void bind(int lport, InetAddress laddr) diff --git a/openjdk/java/net/TwoStacksPlainSocketImpl.java b/openjdk/java/net/TwoStacksPlainSocketImpl.java index 555db486..41790788 100644 --- a/openjdk/java/net/TwoStacksPlainSocketImpl.java +++ b/openjdk/java/net/TwoStacksPlainSocketImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,7 @@ package java.net; import java.io.IOException; import java.io.FileDescriptor; +import sun.net.ResourceManager; /* * This class defines the plain SocketImpl that is used for all @@ -37,7 +38,6 @@ import java.io.FileDescriptor; * during socket creation. * * @author Chris Hegarty - * @author Jeroen Frijters */ class TwoStacksPlainSocketImpl extends AbstractPlainSocketImpl @@ -78,7 +78,12 @@ class TwoStacksPlainSocketImpl extends AbstractPlainSocketImpl */ protected synchronized void create(boolean stream) throws IOException { fd1 = new FileDescriptor(); - super.create(stream); + try { + super.create(stream); + } catch (IOException e) { + fd1 = null; + throw e; + } } /** @@ -117,6 +122,9 @@ class TwoStacksPlainSocketImpl extends AbstractPlainSocketImpl protected void close() throws IOException { synchronized(fdLock) { if (fd != null || fd1 != null) { + if (!stream) { + ResourceManager.afterUdpClose(); + } if (fdUseCount == 0) { if (closePending) { return; diff --git a/openjdk/sun/management/ManagementFactoryHelper.java b/openjdk/sun/management/ManagementFactoryHelper.java index 684a96b1..0e54032d 100644 --- a/openjdk/sun/management/ManagementFactoryHelper.java +++ b/openjdk/sun/management/ManagementFactoryHelper.java @@ -170,7 +170,8 @@ public class ManagementFactoryHelper { ObjectName result = objname; if (result == null) { synchronized (this) { - if (objname == null) { + result = objname; + if (result == null) { result = Util.newObjectName(LOGGING_MXBEAN_NAME); objname = result; } @@ -227,7 +228,8 @@ public class ManagementFactoryHelper { ObjectName result = objname; if (result == null) { synchronized (this) { - if (objname == null) { + result = objname; + if (result == null) { result = Util.newObjectName(BUFFER_POOL_MXBEAN_NAME + ",name=" + pool.getName()); objname = result; diff --git a/openjdk/sun/nio/ch/DatagramChannelImpl.java b/openjdk/sun/nio/ch/DatagramChannelImpl.java index 4fa9796e..a987bbc4 100644 --- a/openjdk/sun/nio/ch/DatagramChannelImpl.java +++ b/openjdk/sun/nio/ch/DatagramChannelImpl.java @@ -505,8 +505,15 @@ class DatagramChannelImpl int rem = (pos <= lim ? lim - pos : 0); boolean preferIPv6 = (family != StandardProtocolFamily.INET); - int written = send0(preferIPv6, fd, bb.array(), bb.arrayOffset() + pos, + int written; + try { + written = send0(preferIPv6, fd, bb.array(), bb.arrayOffset() + pos, rem, target); + } catch (PortUnreachableException pue) { + if (isConnected()) + throw pue; + written = rem; + } if (written > 0) bb.position(pos + written); return written; |