mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-13 17:33:10 +00:00
Merge
This commit is contained in:
commit
5817fca746
1
.hgtags
1
.hgtags
@ -383,3 +383,4 @@ e384420383a5b79fa0012ebcb25d8f83cff7f777 jdk-9+135
|
||||
d273dfe9a126d3bffe92072547fef2cd1361b0eb jdk-9+138
|
||||
65477538bec32963dc41153d89c4417eb46c45fc jdk-9+139
|
||||
0875007901f7d364a08220b052f0c81003e9c8c5 jdk-9+140
|
||||
9aadd2163b568d76f8969ad2fb404a63733da359 jdk-9+141
|
||||
|
||||
@ -383,3 +383,4 @@ d7f519b004254b19e384131d9f0d0e40e31a0fd3 jdk-9+137
|
||||
67c4388142bdf58aec8fefa4475faaa8a5d7380c jdk-9+138
|
||||
7dcf453eacae79ee86a6bcc75fd0b546fc99b48a jdk-9+139
|
||||
a5815c6098a241d3a1df64d22b84b3524e4a77df jdk-9+140
|
||||
f64afae7f1a5608e438585bbf0bc23785e69cba0 jdk-9+141
|
||||
|
||||
@ -895,7 +895,7 @@ AC_DEFUN([FLAGS_SETUP_COMPILER_FLAGS_FOR_JDK_HELPER],
|
||||
elif test "x$OPENJDK_$1_OS" = xsolaris; then
|
||||
$2JVM_CFLAGS="[$]$2JVM_CFLAGS -DSOLARIS"
|
||||
$2JVM_CFLAGS="[$]$2JVM_CFLAGS -template=no%extdef -features=no%split_init \
|
||||
-D_Crun_inline_placement -library=%none -KPIC -mt -xwe -features=no%except"
|
||||
-D_Crun_inline_placement -library=%none -KPIC -mt -features=no%except"
|
||||
elif test "x$OPENJDK_$1_OS" = xmacosx; then
|
||||
$2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -D_ALLBSD_SOURCE -D_DARWIN_UNLIMITED_SELECT"
|
||||
$2JVM_CFLAGS="[$]$2JVM_CFLAGS -D_ALLBSD_SOURCE"
|
||||
|
||||
@ -5093,7 +5093,7 @@ VS_SDK_PLATFORM_NAME_2013=
|
||||
#CUSTOM_AUTOCONF_INCLUDE
|
||||
|
||||
# Do not change or remove the following line, it is needed for consistency checks:
|
||||
DATE_WHEN_GENERATED=1476275292
|
||||
DATE_WHEN_GENERATED=1477108079
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
@ -50077,7 +50077,7 @@ $as_echo "$as_me: GCC >= 6 detected; adding ${NO_DELETE_NULL_POINTER_CHECKS_CFLA
|
||||
elif test "x$OPENJDK_TARGET_OS" = xsolaris; then
|
||||
JVM_CFLAGS="$JVM_CFLAGS -DSOLARIS"
|
||||
JVM_CFLAGS="$JVM_CFLAGS -template=no%extdef -features=no%split_init \
|
||||
-D_Crun_inline_placement -library=%none -KPIC -mt -xwe -features=no%except"
|
||||
-D_Crun_inline_placement -library=%none -KPIC -mt -features=no%except"
|
||||
elif test "x$OPENJDK_TARGET_OS" = xmacosx; then
|
||||
COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS_JDK -D_ALLBSD_SOURCE -D_DARWIN_UNLIMITED_SELECT"
|
||||
JVM_CFLAGS="$JVM_CFLAGS -D_ALLBSD_SOURCE"
|
||||
@ -50892,7 +50892,7 @@ $as_echo "$as_me: GCC >= 6 detected; adding ${NO_DELETE_NULL_POINTER_CHECKS_CFLA
|
||||
elif test "x$OPENJDK_BUILD_OS" = xsolaris; then
|
||||
OPENJDK_BUILD_JVM_CFLAGS="$OPENJDK_BUILD_JVM_CFLAGS -DSOLARIS"
|
||||
OPENJDK_BUILD_JVM_CFLAGS="$OPENJDK_BUILD_JVM_CFLAGS -template=no%extdef -features=no%split_init \
|
||||
-D_Crun_inline_placement -library=%none -KPIC -mt -xwe -features=no%except"
|
||||
-D_Crun_inline_placement -library=%none -KPIC -mt -features=no%except"
|
||||
elif test "x$OPENJDK_BUILD_OS" = xmacosx; then
|
||||
OPENJDK_BUILD_COMMON_CCXXFLAGS_JDK="$OPENJDK_BUILD_COMMON_CCXXFLAGS_JDK -D_ALLBSD_SOURCE -D_DARWIN_UNLIMITED_SELECT"
|
||||
OPENJDK_BUILD_JVM_CFLAGS="$OPENJDK_BUILD_JVM_CFLAGS -D_ALLBSD_SOURCE"
|
||||
|
||||
@ -383,3 +383,4 @@ aa053a3faf266c12b4fd5272da431a3e08e4a3e3 jdk-9+136
|
||||
27bb44be32076861a0951bcefb07a1d92509a4b6 jdk-9+138
|
||||
8c9da7fc5b07c606afd571c7012441b77dda83b2 jdk-9+139
|
||||
9f3fc931bc230f44f2a58d75f7f6360af98bb113 jdk-9+140
|
||||
b32f998da32b488ec7c4e9dbb3c750841b48e74d jdk-9+141
|
||||
|
||||
@ -31,22 +31,17 @@
|
||||
|
||||
package com.sun.corba.se.impl.io;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.StreamCorruptedException;
|
||||
import java.io.ObjectInputValidation;
|
||||
import java.io.NotActiveException;
|
||||
import java.io.InvalidObjectException;
|
||||
import java.io.InvalidClassException;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.OptionalDataException;
|
||||
import java.io.WriteAbortedException;
|
||||
import java.io.Externalizable;
|
||||
import java.io.EOFException;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.Vector;
|
||||
import java.util.Stack;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import sun.corba.Bridge ;
|
||||
@ -54,7 +49,6 @@ import sun.corba.Bridge ;
|
||||
import java.security.AccessController ;
|
||||
import java.security.PrivilegedAction ;
|
||||
|
||||
import com.sun.corba.se.impl.io.ObjectStreamClass;
|
||||
import com.sun.corba.se.impl.util.Utility;
|
||||
|
||||
import org.omg.CORBA.portable.ValueInputStream;
|
||||
@ -71,14 +65,12 @@ import org.omg.CORBA.TypeCode;
|
||||
import com.sun.org.omg.CORBA.ValueDefPackage.FullValueDescription;
|
||||
import com.sun.org.omg.SendingContext.CodeBase;
|
||||
|
||||
import javax.rmi.PortableRemoteObject;
|
||||
import javax.rmi.CORBA.Util;
|
||||
import javax.rmi.CORBA.ValueHandler;
|
||||
|
||||
import java.security.*;
|
||||
import java.util.*;
|
||||
|
||||
import com.sun.corba.se.impl.orbutil.ObjectUtility ;
|
||||
import com.sun.corba.se.impl.logging.OMGSystemException ;
|
||||
import com.sun.corba.se.impl.logging.UtilSystemException ;
|
||||
|
||||
@ -182,75 +174,6 @@ public class IIOPInputStream
|
||||
|
||||
private byte streamFormatVersion;
|
||||
|
||||
// Since java.io.OptionalDataException's constructors are
|
||||
// package private, but we need to throw it in some special
|
||||
// cases, we try to do it by reflection.
|
||||
private static final Constructor OPT_DATA_EXCEPTION_CTOR;
|
||||
|
||||
private Object[] readObjectArgList = { this } ;
|
||||
|
||||
static {
|
||||
OPT_DATA_EXCEPTION_CTOR = getOptDataExceptionCtor();
|
||||
}
|
||||
|
||||
// Grab the OptionalDataException boolean ctor and make
|
||||
// it accessible. Note that any exceptions
|
||||
// will be wrapped in ExceptionInInitializerErrors.
|
||||
private static Constructor getOptDataExceptionCtor() {
|
||||
|
||||
try {
|
||||
|
||||
Constructor result =
|
||||
|
||||
(Constructor) AccessController.doPrivileged(
|
||||
new PrivilegedExceptionAction() {
|
||||
public java.lang.Object run()
|
||||
throws NoSuchMethodException,
|
||||
SecurityException {
|
||||
|
||||
Constructor boolCtor
|
||||
= OptionalDataException.class.getDeclaredConstructor(
|
||||
new Class[] {
|
||||
Boolean.TYPE });
|
||||
|
||||
boolCtor.setAccessible(true);
|
||||
|
||||
return boolCtor;
|
||||
}});
|
||||
|
||||
if (result == null)
|
||||
// XXX I18N, logging needed.
|
||||
throw new Error("Unable to find OptionalDataException constructor");
|
||||
|
||||
return result;
|
||||
|
||||
} catch (Exception ex) {
|
||||
// XXX I18N, logging needed.
|
||||
throw new ExceptionInInitializerError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new OptionalDataException with the EOF marker
|
||||
// set to true. See handleOptionalDataMarshalException.
|
||||
private OptionalDataException createOptionalDataException() {
|
||||
try {
|
||||
OptionalDataException result
|
||||
= (OptionalDataException)
|
||||
OPT_DATA_EXCEPTION_CTOR.newInstance(new Object[] {
|
||||
Boolean.TRUE });
|
||||
|
||||
if (result == null)
|
||||
// XXX I18N, logging needed.
|
||||
throw new Error("Created null OptionalDataException");
|
||||
|
||||
return result;
|
||||
|
||||
} catch (Exception ex) {
|
||||
// XXX I18N, logging needed.
|
||||
throw new Error("Couldn't create OptionalDataException", ex);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the stream format version currently being used
|
||||
// to deserialize an object
|
||||
protected byte getStreamFormatVersion() {
|
||||
@ -395,7 +318,6 @@ public class IIOPInputStream
|
||||
int offset)
|
||||
/* throws OptionalDataException, ClassNotFoundException, IOException */
|
||||
{
|
||||
|
||||
/* Save the current state and get ready to read an object. */
|
||||
Object prevObject = currentObject;
|
||||
ObjectStreamClass prevClassDesc = currentClassDesc;
|
||||
@ -947,7 +869,7 @@ public class IIOPInputStream
|
||||
if (!objectRead)
|
||||
result = new EOFException("No more optional data");
|
||||
else
|
||||
result = createOptionalDataException();
|
||||
result = bridge.newOptionalDataExceptionForSerialization(true);
|
||||
|
||||
result.initCause(marshalException);
|
||||
|
||||
@ -1230,8 +1152,7 @@ public class IIOPInputStream
|
||||
|
||||
readObjectState.beginUnmarshalCustomValue(this,
|
||||
calledDefaultWriteObject,
|
||||
(currentClassDesc.readObjectMethod
|
||||
!= null));
|
||||
currentClassDesc.hasReadObject());
|
||||
} else {
|
||||
if (currentClassDesc.hasReadObject())
|
||||
setState(IN_READ_OBJECT_REMOTE_NOT_CUSTOM_MARSHALED);
|
||||
@ -1556,8 +1477,7 @@ public class IIOPInputStream
|
||||
|
||||
readObjectState.beginUnmarshalCustomValue(this,
|
||||
calledDefaultWriteObject,
|
||||
(currentClassDesc.readObjectMethod
|
||||
!= null));
|
||||
currentClassDesc.hasReadObject());
|
||||
}
|
||||
|
||||
boolean usedReadObject = false;
|
||||
@ -1714,13 +1634,8 @@ public class IIOPInputStream
|
||||
throws InvalidClassException, StreamCorruptedException,
|
||||
ClassNotFoundException, IOException
|
||||
{
|
||||
if (osc.readObjectMethod == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
osc.readObjectMethod.invoke( obj, readObjectArgList ) ;
|
||||
return true;
|
||||
return osc.invokeReadObject( obj, this ) ;
|
||||
} catch (InvocationTargetException e) {
|
||||
Throwable t = e.getTargetException();
|
||||
if (t instanceof ClassNotFoundException)
|
||||
@ -1734,8 +1649,6 @@ public class IIOPInputStream
|
||||
else
|
||||
// XXX I18N, logging needed.
|
||||
throw new Error("internal error");
|
||||
} catch (IllegalAccessException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -31,33 +31,23 @@
|
||||
|
||||
package com.sun.corba.se.impl.io;
|
||||
|
||||
import org.omg.CORBA.INTERNAL;
|
||||
import org.omg.CORBA.portable.OutputStream;
|
||||
|
||||
import java.security.AccessController ;
|
||||
import java.security.PrivilegedAction ;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.InvalidClassException;
|
||||
import java.io.StreamCorruptedException;
|
||||
import java.io.Externalizable;
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.NotSerializableException;
|
||||
import java.io.NotActiveException;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
import javax.rmi.CORBA.Util;
|
||||
import javax.rmi.CORBA.ValueHandlerMultiFormat;
|
||||
|
||||
import sun.corba.Bridge ;
|
||||
|
||||
import com.sun.corba.se.impl.io.ObjectStreamClass;
|
||||
import com.sun.corba.se.impl.util.Utility;
|
||||
import com.sun.corba.se.impl.util.RepositoryId;
|
||||
|
||||
@ -621,7 +611,7 @@ public class IIOPOutputStream
|
||||
writeObjectState.enterWriteObject(this);
|
||||
|
||||
// writeObject(obj, c, this);
|
||||
osc.writeObjectMethod.invoke( obj, writeObjectArgList ) ;
|
||||
osc.invokeWriteObject( obj, this ) ;
|
||||
|
||||
writeObjectState.exitWriteObject(this);
|
||||
|
||||
@ -636,8 +626,6 @@ public class IIOPOutputStream
|
||||
else
|
||||
// XXX I18N, Logging needed.
|
||||
throw new Error("invokeObjectWriter internal error",e);
|
||||
} catch (IllegalAccessException e) {
|
||||
// cannot happen
|
||||
}
|
||||
}
|
||||
|
||||
@ -761,59 +749,52 @@ public class IIOPOutputStream
|
||||
*/
|
||||
private void outputClassFields(Object o, Class cl,
|
||||
ObjectStreamField[] fields)
|
||||
throws IOException, InvalidClassException {
|
||||
throws IOException {
|
||||
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
if (fields[i].getField() == null)
|
||||
// XXX I18N, Logging needed.
|
||||
throw new InvalidClassException(cl.getName(),
|
||||
"Nonexistent field " + fields[i].getName());
|
||||
|
||||
try {
|
||||
switch (fields[i].getTypeCode()) {
|
||||
case 'B':
|
||||
byte byteValue = fields[i].getField().getByte( o ) ;
|
||||
orbStream.write_octet(byteValue);
|
||||
break;
|
||||
case 'C':
|
||||
char charValue = fields[i].getField().getChar( o ) ;
|
||||
orbStream.write_wchar(charValue);
|
||||
break;
|
||||
case 'F':
|
||||
float floatValue = fields[i].getField().getFloat( o ) ;
|
||||
orbStream.write_float(floatValue);
|
||||
break;
|
||||
case 'D' :
|
||||
double doubleValue = fields[i].getField().getDouble( o ) ;
|
||||
orbStream.write_double(doubleValue);
|
||||
break;
|
||||
case 'I':
|
||||
int intValue = fields[i].getField().getInt( o ) ;
|
||||
orbStream.write_long(intValue);
|
||||
break;
|
||||
case 'J':
|
||||
long longValue = fields[i].getField().getLong( o ) ;
|
||||
orbStream.write_longlong(longValue);
|
||||
break;
|
||||
case 'S':
|
||||
short shortValue = fields[i].getField().getShort( o ) ;
|
||||
orbStream.write_short(shortValue);
|
||||
break;
|
||||
case 'Z':
|
||||
boolean booleanValue = fields[i].getField().getBoolean( o ) ;
|
||||
orbStream.write_boolean(booleanValue);
|
||||
break;
|
||||
case '[':
|
||||
case 'L':
|
||||
Object objectValue = fields[i].getField().get( o ) ;
|
||||
writeObjectField(fields[i], objectValue);
|
||||
break;
|
||||
default:
|
||||
// XXX I18N, Logging needed.
|
||||
throw new InvalidClassException(cl.getName());
|
||||
}
|
||||
} catch (IllegalAccessException exc) {
|
||||
throw wrapper.illegalFieldAccess( exc, fields[i].getName() ) ;
|
||||
switch (fields[i].getTypeCode()) {
|
||||
case 'B':
|
||||
byte byteValue = bridge.getByte(o, fields[i].getFieldID()) ;
|
||||
orbStream.write_octet(byteValue);
|
||||
break;
|
||||
case 'C':
|
||||
char charValue = bridge.getChar(o, fields[i].getFieldID()) ;
|
||||
orbStream.write_wchar(charValue);
|
||||
break;
|
||||
case 'F':
|
||||
float floatValue = bridge.getFloat(o, fields[i].getFieldID()) ;
|
||||
orbStream.write_float(floatValue);
|
||||
break;
|
||||
case 'D' :
|
||||
double doubleValue = bridge.getDouble(o, fields[i].getFieldID()) ;
|
||||
orbStream.write_double(doubleValue);
|
||||
break;
|
||||
case 'I':
|
||||
int intValue = bridge.getInt(o, fields[i].getFieldID()) ;
|
||||
orbStream.write_long(intValue);
|
||||
break;
|
||||
case 'J':
|
||||
long longValue = bridge.getLong(o, fields[i].getFieldID()) ;
|
||||
orbStream.write_longlong(longValue);
|
||||
break;
|
||||
case 'S':
|
||||
short shortValue = bridge.getShort(o, fields[i].getFieldID()) ;
|
||||
orbStream.write_short(shortValue);
|
||||
break;
|
||||
case 'Z':
|
||||
boolean booleanValue = bridge.getBoolean(o, fields[i].getFieldID()) ;
|
||||
orbStream.write_boolean(booleanValue);
|
||||
break;
|
||||
case '[':
|
||||
case 'L':
|
||||
Object objectValue = bridge.getObject(o, fields[i].getFieldID()) ;
|
||||
writeObjectField(fields[i], objectValue);
|
||||
break;
|
||||
default:
|
||||
throw new InvalidClassException(cl.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,16 +31,16 @@
|
||||
|
||||
package com.sun.corba.se.impl.io;
|
||||
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.DigestOutputStream;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Method;
|
||||
@ -80,9 +80,6 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
|
||||
public static final long kDefaultUID = -1;
|
||||
|
||||
private static Object noArgsList[] = {};
|
||||
private static Class<?> noTypesList[] = {};
|
||||
|
||||
/** true if represents enum type */
|
||||
private boolean isEnum;
|
||||
|
||||
@ -311,12 +308,37 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
return null;
|
||||
}
|
||||
|
||||
public final boolean invokeWriteObject(Object obj, ObjectOutputStream ois) throws InvocationTargetException {
|
||||
if (!hasWriteObject()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
writeObjectMethod.invoke(obj, ois);
|
||||
} catch (Throwable t) {
|
||||
throw new InvocationTargetException(t, "writeObject");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public final boolean invokeReadObject(Object obj, ObjectInputStream ois) throws InvocationTargetException {
|
||||
if (hasReadObject()) {
|
||||
try {
|
||||
readObjectMethod.invoke(obj, ois);
|
||||
return true;
|
||||
} catch (Throwable t) {
|
||||
throw new InvocationTargetException(t, "readObject");
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Serializable writeReplace(Serializable value) {
|
||||
if (writeReplaceObjectMethod != null) {
|
||||
try {
|
||||
return (Serializable) writeReplaceObjectMethod.invoke(value,noArgsList);
|
||||
} catch(Throwable t) {
|
||||
throw new RuntimeException(t);
|
||||
return (Serializable) writeReplaceObjectMethod.invoke(value);
|
||||
} catch (Throwable t) {
|
||||
throw new InternalError("unexpected error", t);
|
||||
}
|
||||
}
|
||||
else return value;
|
||||
@ -325,9 +347,9 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
public Object readResolve(Object value) {
|
||||
if (readResolveObjectMethod != null) {
|
||||
try {
|
||||
return readResolveObjectMethod.invoke(value,noArgsList);
|
||||
} catch(Throwable t) {
|
||||
throw new RuntimeException(t);
|
||||
return readResolveObjectMethod.invoke(value);
|
||||
} catch (Throwable t) {
|
||||
throw new InternalError("unexpected error", t);
|
||||
}
|
||||
}
|
||||
else return value;
|
||||
@ -382,31 +404,34 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
*/
|
||||
}
|
||||
|
||||
private static final class PersistentFieldsValue
|
||||
static final class PersistentFieldsValue
|
||||
extends ClassValue<ObjectStreamField[]> {
|
||||
PersistentFieldsValue() { }
|
||||
|
||||
protected ObjectStreamField[] computeValue(Class<?> type) {
|
||||
try {
|
||||
bridge.ensureClassInitialized(type);
|
||||
Field pf = type.getDeclaredField("serialPersistentFields");
|
||||
int mods = pf.getModifiers();
|
||||
if (Modifier.isPrivate(mods) && Modifier.isStatic(mods) &&
|
||||
Modifier.isFinal(mods)) {
|
||||
pf.setAccessible(true);
|
||||
long offset = bridge.staticFieldOffset(pf);
|
||||
java.io.ObjectStreamField[] fields =
|
||||
(java.io.ObjectStreamField[])pf.get(type);
|
||||
(java.io.ObjectStreamField[])bridge.getObject(type, offset);
|
||||
return translateFields(fields);
|
||||
}
|
||||
} catch (NoSuchFieldException | IllegalAccessException |
|
||||
} catch (NoSuchFieldException |
|
||||
IllegalArgumentException | ClassCastException e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ObjectStreamField[] translateFields(
|
||||
java.io.ObjectStreamField[] fields) {
|
||||
private static ObjectStreamField[] translateFields(java.io.ObjectStreamField[] fields) {
|
||||
if (fields == null) {
|
||||
return null;
|
||||
}
|
||||
ObjectStreamField[] translation =
|
||||
new ObjectStreamField[fields.length];
|
||||
new ObjectStreamField[fields.length];
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
translation[i] = new ObjectStreamField(fields[i].getName(),
|
||||
fields[i].getType());
|
||||
@ -450,13 +475,11 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
* If it is declared, use the declared serialPersistentFields.
|
||||
* Otherwise, extract the fields from the class itself.
|
||||
*/
|
||||
fields = persistentFieldsValue.get(cl);
|
||||
fields = persistentFieldsValue.get(cl);
|
||||
|
||||
if (fields == null) {
|
||||
/* Get all of the declared fields for this
|
||||
* Class. setAccessible on all fields so they
|
||||
* can be accessed later. Create a temporary
|
||||
* ObjectStreamField array to hold each
|
||||
/* Get all of the declared fields for this Class.
|
||||
* Create a temporary ObjectStreamField array to hold each
|
||||
* non-static, non-transient field. Then copy the
|
||||
* temporary array into an array of the correct
|
||||
* size once the number of fields is known.
|
||||
@ -471,7 +494,6 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
int modifiers = fld.getModifiers();
|
||||
if (!Modifier.isStatic(modifiers) &&
|
||||
!Modifier.isTransient(modifiers)) {
|
||||
fld.setAccessible(true) ;
|
||||
tempFields[numFields++] = new ObjectStreamField(fld);
|
||||
}
|
||||
}
|
||||
@ -487,7 +509,6 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
try {
|
||||
Field reflField = cl.getDeclaredField(fields[j].getName());
|
||||
if (fields[j].getType() == reflField.getType()) {
|
||||
reflField.setAccessible(true);
|
||||
fields[j].setField(reflField);
|
||||
}
|
||||
} catch (NoSuchFieldException e) {
|
||||
@ -527,8 +548,8 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
int mods = f.getModifiers();
|
||||
// SerialBug 5: static final SUID should be read
|
||||
if (Modifier.isStatic(mods) && Modifier.isFinal(mods) ) {
|
||||
f.setAccessible(true);
|
||||
suid = f.getLong(cl);
|
||||
long offset = bridge.staticFieldOffset(f);
|
||||
suid = bridge.getLong(cl, offset);
|
||||
// SerialBug 2: should be computed after writeObject
|
||||
// actualSuid = computeStructuralUID(cl);
|
||||
} else {
|
||||
@ -540,16 +561,12 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
suid = _computeSerialVersionUID(cl);
|
||||
// SerialBug 2: should be computed after writeObject
|
||||
// actualSuid = computeStructuralUID(cl);
|
||||
} catch (IllegalAccessException ex) {
|
||||
suid = _computeSerialVersionUID(cl);
|
||||
}
|
||||
}
|
||||
|
||||
writeReplaceObjectMethod = ObjectStreamClass.getInheritableMethod(cl,
|
||||
"writeReplace", noTypesList, Object.class);
|
||||
writeReplaceObjectMethod = bridge.writeReplaceForSerialization(cl);
|
||||
|
||||
readResolveObjectMethod = ObjectStreamClass.getInheritableMethod(cl,
|
||||
"readResolve", noTypesList, Object.class);
|
||||
readResolveObjectMethod = bridge.readResolveForSerialization(cl);
|
||||
|
||||
if (externalizable)
|
||||
cons = getExternalizableConstructor(cl) ;
|
||||
@ -557,14 +574,8 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
cons = getSerializableConstructor(cl) ;
|
||||
|
||||
if (serializable && !forProxyClass) {
|
||||
/* Look for the writeObject method
|
||||
* Set the accessible flag on it here. ObjectOutputStream
|
||||
* will call it as necessary.
|
||||
*/
|
||||
writeObjectMethod = getPrivateMethod( cl, "writeObject",
|
||||
new Class<?>[] { java.io.ObjectOutputStream.class }, Void.TYPE ) ;
|
||||
readObjectMethod = getPrivateMethod( cl, "readObject",
|
||||
new Class<?>[] { java.io.ObjectInputStream.class }, Void.TYPE ) ;
|
||||
writeObjectMethod = bridge.writeObjectForSerialization(cl) ;
|
||||
readObjectMethod = bridge.readObjectForSerialization(cl);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -585,27 +596,6 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns non-static private method with given signature defined by given
|
||||
* class, or null if none found. Access checks are disabled on the
|
||||
* returned method (if any).
|
||||
*/
|
||||
private static Method getPrivateMethod(Class<?> cl, String name,
|
||||
Class<?>[] argTypes,
|
||||
Class<?> returnType)
|
||||
{
|
||||
try {
|
||||
Method meth = cl.getDeclaredMethod(name, argTypes);
|
||||
meth.setAccessible(true);
|
||||
int mods = meth.getModifiers();
|
||||
return ((meth.getReturnType() == returnType) &&
|
||||
((mods & Modifier.STATIC) == 0) &&
|
||||
((mods & Modifier.PRIVATE) != 0)) ? meth : null;
|
||||
} catch (NoSuchMethodException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Specific to RMI-IIOP
|
||||
/**
|
||||
* Java to IDL ptc-02-01-12 1.5.1
|
||||
@ -848,6 +838,22 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
return writeObjectMethod != null ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if represented class is serializable or externalizable and
|
||||
* defines a conformant writeReplace method. Otherwise, returns false.
|
||||
*/
|
||||
boolean hasWriteReplaceMethod() {
|
||||
return (writeReplaceObjectMethod != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if represented class is serializable or externalizable and
|
||||
* defines a conformant readResolve method. Otherwise, returns false.
|
||||
*/
|
||||
boolean hasReadResolveMethod() {
|
||||
return (readResolveObjectMethod != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns when or not this class should be custom
|
||||
* marshaled (use chunking). This should happen if
|
||||
@ -904,7 +910,7 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
{
|
||||
if (cons != null) {
|
||||
try {
|
||||
return cons.newInstance(new Object[0]);
|
||||
return cons.newInstance();
|
||||
} catch (IllegalAccessException ex) {
|
||||
// should not occur, as access checks have been suppressed
|
||||
InternalError ie = new InternalError();
|
||||
@ -912,7 +918,7 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
throw ie ;
|
||||
}
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
throw new UnsupportedOperationException("no constructor for " + ofClass);
|
||||
}
|
||||
}
|
||||
|
||||
@ -921,15 +927,8 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
* Access checks are disabled on the returned constructor (if any), since
|
||||
* the defining class may still be non-public.
|
||||
*/
|
||||
private static Constructor getExternalizableConstructor(Class<?> cl) {
|
||||
try {
|
||||
Constructor cons = cl.getDeclaredConstructor(new Class<?>[0]);
|
||||
cons.setAccessible(true);
|
||||
return ((cons.getModifiers() & Modifier.PUBLIC) != 0) ?
|
||||
cons : null;
|
||||
} catch (NoSuchMethodException ex) {
|
||||
return null;
|
||||
}
|
||||
private static Constructor<?> getExternalizableConstructor(Class<?> cl) {
|
||||
return bridge.newConstructorForExternalization(cl);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -937,28 +936,8 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
* superclass, or null if none found. Access checks are disabled on the
|
||||
* returned constructor (if any).
|
||||
*/
|
||||
private static Constructor getSerializableConstructor(Class<?> cl) {
|
||||
Class<?> initCl = cl;
|
||||
while (Serializable.class.isAssignableFrom(initCl)) {
|
||||
if ((initCl = initCl.getSuperclass()) == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
try {
|
||||
Constructor cons = initCl.getDeclaredConstructor(new Class<?>[0]);
|
||||
int mods = cons.getModifiers();
|
||||
if ((mods & Modifier.PRIVATE) != 0 ||
|
||||
((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
|
||||
!packageEquals(cl, initCl)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
cons = bridge.newConstructorForSerialization(cl, cons);
|
||||
cons.setAccessible(true);
|
||||
return cons;
|
||||
} catch (NoSuchMethodException ex) {
|
||||
return null;
|
||||
}
|
||||
private static Constructor<?> getSerializableConstructor(Class<?> cl) {
|
||||
return bridge.newConstructorForSerialization(cl);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1522,11 +1501,11 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
* @since JDK 1.2
|
||||
*/
|
||||
private boolean hasExternalizableBlockData;
|
||||
Method writeObjectMethod;
|
||||
Method readObjectMethod;
|
||||
private transient Method writeReplaceObjectMethod;
|
||||
private transient Method readResolveObjectMethod;
|
||||
private Constructor cons ;
|
||||
private transient MethodHandle writeObjectMethod;
|
||||
private transient MethodHandle readObjectMethod;
|
||||
private transient MethodHandle writeReplaceObjectMethod;
|
||||
private transient MethodHandle readResolveObjectMethod;
|
||||
private transient Constructor<?> cons;
|
||||
|
||||
/**
|
||||
* Beginning in Java to IDL ptc/02-01-12, RMI-IIOP has a
|
||||
@ -1543,44 +1522,12 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
*/
|
||||
private ObjectStreamClass localClassDesc;
|
||||
|
||||
/* Find out if the class has a static class initializer <clinit> */
|
||||
private static Method hasStaticInitializerMethod = null;
|
||||
/**
|
||||
* Returns true if the given class defines a static initializer method,
|
||||
* false otherwise.
|
||||
*/
|
||||
private static boolean hasStaticInitializer(Class<?> cl) {
|
||||
if (hasStaticInitializerMethod == null) {
|
||||
Class<?> classWithThisMethod = null;
|
||||
|
||||
try {
|
||||
if (classWithThisMethod == null)
|
||||
classWithThisMethod = java.io.ObjectStreamClass.class;
|
||||
|
||||
hasStaticInitializerMethod =
|
||||
classWithThisMethod.getDeclaredMethod("hasStaticInitializer",
|
||||
new Class<?>[] { Class.class });
|
||||
} catch (NoSuchMethodException ex) {
|
||||
}
|
||||
|
||||
if (hasStaticInitializerMethod == null) {
|
||||
// XXX I18N, logging needed
|
||||
throw new InternalError("Can't find hasStaticInitializer method on "
|
||||
+ classWithThisMethod.getName());
|
||||
}
|
||||
hasStaticInitializerMethod.setAccessible(true);
|
||||
}
|
||||
|
||||
try {
|
||||
Boolean retval = (Boolean)
|
||||
hasStaticInitializerMethod.invoke(null, new Object[] { cl });
|
||||
return retval.booleanValue();
|
||||
} catch (Exception ex) {
|
||||
// XXX I18N, logging needed
|
||||
InternalError ie = new InternalError( "Error invoking hasStaticInitializer" ) ;
|
||||
ie.initCause( ex ) ;
|
||||
throw ie ;
|
||||
}
|
||||
return bridge.hasStaticInitializerForSerialization(cl);
|
||||
}
|
||||
|
||||
|
||||
@ -1754,7 +1701,6 @@ public class ObjectStreamClass implements java.io.Serializable {
|
||||
if ((meth == null) || (meth.getReturnType() != returnType)) {
|
||||
return null;
|
||||
}
|
||||
meth.setAccessible(true);
|
||||
int mods = meth.getModifiers();
|
||||
if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0) {
|
||||
return null;
|
||||
|
||||
@ -32,6 +32,7 @@ module java.corba {
|
||||
requires java.logging;
|
||||
requires java.naming;
|
||||
requires java.transaction;
|
||||
requires jdk.unsupported;
|
||||
|
||||
exports javax.activity;
|
||||
exports javax.rmi;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2004, 2016, 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
|
||||
@ -25,25 +25,24 @@
|
||||
|
||||
package sun.corba ;
|
||||
|
||||
import java.io.OptionalDataException;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.reflect.Field ;
|
||||
import java.lang.reflect.Method ;
|
||||
import java.lang.reflect.Constructor ;
|
||||
import java.lang.reflect.InvocationTargetException ;
|
||||
|
||||
import java.io.ObjectInputStream ;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.Permission;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
import jdk.internal.misc.Unsafe ;
|
||||
import jdk.internal.reflect.ReflectionFactory;
|
||||
import sun.misc.Unsafe;
|
||||
import sun.reflect.ReflectionFactory;
|
||||
|
||||
/** This class provides the methods for fundamental JVM operations
|
||||
* needed in the ORB that are not part of the public Java API. This includes:
|
||||
* <ul>
|
||||
* <li>throwException, which can throw undeclared checked exceptions.
|
||||
* This is needed to handle throwing arbitrary exceptions across a standardized OMG interface that (incorrectly) does not specify appropriate exceptions.</li>
|
||||
* This is needed to handle throwing arbitrary exceptions across a standardized
|
||||
* OMG interface that (incorrectly) does not specify appropriate exceptions.</li>
|
||||
* <li>putXXX/getXXX methods that allow unchecked access to fields of objects.
|
||||
* This is used for setting uninitialzed non-static final fields (which is
|
||||
* impossible with reflection) and for speed.</li>
|
||||
@ -71,88 +70,28 @@ import jdk.internal.reflect.ReflectionFactory;
|
||||
*/
|
||||
public final class Bridge
|
||||
{
|
||||
private static final Class[] NO_ARGS = new Class[] {};
|
||||
private static final Permission getBridgePermission =
|
||||
new BridgePermission( "getBridge" ) ;
|
||||
new BridgePermission("getBridge");
|
||||
private static Bridge bridge = null ;
|
||||
|
||||
// latestUserDefinedLoader() is a private static method
|
||||
// in ObjectInputStream in JDK 1.3 through 1.5.
|
||||
// We use reflection in a doPrivileged block to get a
|
||||
// Method reference and make it accessible.
|
||||
private final Method latestUserDefinedLoaderMethod ;
|
||||
private final Unsafe unsafe ;
|
||||
/** Access to Unsafe to read/write fields. */
|
||||
private static final Unsafe unsafe = AccessController.doPrivileged(
|
||||
(PrivilegedAction<Unsafe>)() -> {
|
||||
try {
|
||||
Field field = Unsafe.class.getDeclaredField("theUnsafe");
|
||||
field.setAccessible(true);
|
||||
return (Unsafe)field.get(null);
|
||||
|
||||
} catch (NoSuchFieldException |IllegalAccessException ex) {
|
||||
throw new InternalError("Unsafe.theUnsafe field not available", ex);
|
||||
}
|
||||
}
|
||||
) ;
|
||||
|
||||
private final ReflectionFactory reflectionFactory ;
|
||||
|
||||
private Method getLatestUserDefinedLoaderMethod()
|
||||
{
|
||||
return (Method) AccessController.doPrivileged(
|
||||
new PrivilegedAction()
|
||||
{
|
||||
public Object run()
|
||||
{
|
||||
Method result = null;
|
||||
|
||||
try {
|
||||
Class io = ObjectInputStream.class;
|
||||
result = io.getDeclaredMethod(
|
||||
"latestUserDefinedLoader", NO_ARGS);
|
||||
result.setAccessible(true);
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
Error err = new Error( "java.io.ObjectInputStream" +
|
||||
" latestUserDefinedLoader " + nsme );
|
||||
err.initCause(nsme) ;
|
||||
throw err ;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private Unsafe getUnsafe() {
|
||||
Field fld = (Field)AccessController.doPrivileged(
|
||||
new PrivilegedAction()
|
||||
{
|
||||
public Object run()
|
||||
{
|
||||
Field fld = null ;
|
||||
|
||||
try {
|
||||
Class unsafeClass = jdk.internal.misc.Unsafe.class ;
|
||||
fld = unsafeClass.getDeclaredField( "theUnsafe" ) ;
|
||||
fld.setAccessible( true ) ;
|
||||
return fld ;
|
||||
} catch (NoSuchFieldException exc) {
|
||||
Error err = new Error( "Could not access Unsafe" ) ;
|
||||
err.initCause( exc ) ;
|
||||
throw err ;
|
||||
}
|
||||
}
|
||||
}
|
||||
) ;
|
||||
|
||||
Unsafe unsafe = null;
|
||||
|
||||
try {
|
||||
unsafe = (Unsafe)(fld.get( null )) ;
|
||||
} catch (Throwable t) {
|
||||
Error err = new Error( "Could not access Unsafe" ) ;
|
||||
err.initCause( t ) ;
|
||||
throw err ;
|
||||
}
|
||||
|
||||
return unsafe ;
|
||||
}
|
||||
|
||||
|
||||
private Bridge()
|
||||
{
|
||||
latestUserDefinedLoaderMethod = getLatestUserDefinedLoaderMethod();
|
||||
unsafe = getUnsafe() ;
|
||||
reflectionFactory = (ReflectionFactory)AccessController.doPrivileged(
|
||||
new ReflectionFactory.GetReflectionFactoryAction());
|
||||
private Bridge() {
|
||||
reflectionFactory = ReflectionFactory.getReflectionFactory();
|
||||
}
|
||||
|
||||
/** Fetch the Bridge singleton. This requires the following
|
||||
@ -182,23 +121,8 @@ public final class Bridge
|
||||
/** Obtain the latest user defined ClassLoader from the call stack.
|
||||
* This is required by the RMI-IIOP specification.
|
||||
*/
|
||||
public final ClassLoader getLatestUserDefinedLoader()
|
||||
{
|
||||
try {
|
||||
// Invoke the ObjectInputStream.latestUserDefinedLoader method
|
||||
return (ClassLoader)latestUserDefinedLoaderMethod.invoke(null,
|
||||
(Object[])NO_ARGS);
|
||||
} catch (InvocationTargetException ite) {
|
||||
Error err = new Error(
|
||||
"sun.corba.Bridge.latestUserDefinedLoader: " + ite ) ;
|
||||
err.initCause( ite ) ;
|
||||
throw err ;
|
||||
} catch (IllegalAccessException iae) {
|
||||
Error err = new Error(
|
||||
"sun.corba.Bridge.latestUserDefinedLoader: " + iae ) ;
|
||||
err.initCause( iae ) ;
|
||||
throw err ;
|
||||
}
|
||||
public final ClassLoader getLatestUserDefinedLoader() {
|
||||
return jdk.internal.misc.VM.latestUserDefinedLoader();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -345,6 +269,23 @@ public final class Bridge
|
||||
return unsafe.objectFieldOffset( f ) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset of a static field.
|
||||
*/
|
||||
public final long staticFieldOffset(Field f)
|
||||
{
|
||||
return unsafe.staticFieldOffset( f ) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the class has been initalized.
|
||||
* @param cl the class to ensure is initialized
|
||||
*/
|
||||
public final void ensureClassInitialized(Class<?> cl) {
|
||||
unsafe.ensureClassInitialized(cl);
|
||||
}
|
||||
|
||||
|
||||
/** Throw the exception.
|
||||
* The exception may be an undeclared checked exception.
|
||||
*/
|
||||
@ -353,16 +294,55 @@ public final class Bridge
|
||||
unsafe.throwException( ee ) ;
|
||||
}
|
||||
|
||||
/** Obtain a constructor for Class cl using constructor cons which
|
||||
* may be the constructor defined in a superclass of cl. This is
|
||||
* used to create a constructor for Serializable classes that
|
||||
* constructs an instance of the Serializable class using the
|
||||
/**
|
||||
* Obtain a constructor for Class cl.
|
||||
* This is used to create a constructor for Serializable classes that
|
||||
* construct an instance of the Serializable class using the
|
||||
* no args constructor of the first non-Serializable superclass
|
||||
* of the Serializable class.
|
||||
*/
|
||||
public final Constructor newConstructorForSerialization( Class cl,
|
||||
Constructor cons )
|
||||
{
|
||||
return reflectionFactory.newConstructorForSerialization( cl, cons ) ;
|
||||
public final Constructor<?> newConstructorForSerialization( Class<?> cl ) {
|
||||
return reflectionFactory.newConstructorForSerialization( cl ) ;
|
||||
}
|
||||
|
||||
public final Constructor<?> newConstructorForExternalization(Class<?> cl) {
|
||||
return reflectionFactory.newConstructorForExternalization( cl ) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given class defines a static initializer method,
|
||||
* false otherwise.
|
||||
*/
|
||||
public final boolean hasStaticInitializerForSerialization(Class<?> cl) {
|
||||
return reflectionFactory.hasStaticInitializerForSerialization(cl);
|
||||
}
|
||||
|
||||
public final MethodHandle writeObjectForSerialization(Class<?> cl) {
|
||||
return reflectionFactory.writeObjectForSerialization(cl);
|
||||
}
|
||||
|
||||
public final MethodHandle readObjectForSerialization(Class<?> cl) {
|
||||
return reflectionFactory.readObjectForSerialization(cl);
|
||||
}
|
||||
|
||||
public final MethodHandle readObjectNoDataForSerialization(Class<?> cl) {
|
||||
return reflectionFactory.readObjectNoDataForSerialization(cl);
|
||||
}
|
||||
|
||||
public final MethodHandle readResolveForSerialization(Class<?> cl) {
|
||||
return reflectionFactory.readResolveForSerialization(cl);
|
||||
}
|
||||
|
||||
public final MethodHandle writeReplaceForSerialization(Class<?> cl) {
|
||||
return reflectionFactory.writeReplaceForSerialization(cl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new OptionalDataException instance.
|
||||
* @return a new OptionalDataException instance
|
||||
*/
|
||||
public final OptionalDataException newOptionalDataExceptionForSerialization(boolean bool) {
|
||||
return reflectionFactory.newOptionalDataExceptionForSerialization(bool);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -25,13 +25,13 @@
|
||||
|
||||
package sun.corba;
|
||||
|
||||
import com.sun.corba.se.impl.io.ValueUtility;
|
||||
import jdk.internal.misc.Unsafe;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
import com.sun.corba.se.impl.io.ValueUtility;
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
/** A repository of "shared secrets", which are a mechanism for
|
||||
calling implementation-private methods in another package without
|
||||
using reflection. A package-private class implements a public
|
||||
@ -43,22 +43,22 @@ import java.security.PrivilegedAction;
|
||||
|
||||
// SharedSecrets cloned in corba repo to avoid build issues
|
||||
public class SharedSecrets {
|
||||
private static final Unsafe unsafe = getUnsafe();
|
||||
private static JavaCorbaAccess javaCorbaAccess;
|
||||
|
||||
private static Unsafe getUnsafe() {
|
||||
PrivilegedAction<Unsafe> pa = () -> {
|
||||
Class<?> unsafeClass = jdk.internal.misc.Unsafe.class ;
|
||||
try {
|
||||
Field f = unsafeClass.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
return (Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
};
|
||||
return AccessController.doPrivileged(pa);
|
||||
}
|
||||
/** Access to Unsafe to read/write fields. */
|
||||
private static final Unsafe unsafe = AccessController.doPrivileged(
|
||||
(PrivilegedAction<Unsafe>)() -> {
|
||||
try {
|
||||
Field field = Unsafe.class.getDeclaredField("theUnsafe");
|
||||
field.setAccessible(true);
|
||||
return (Unsafe)field.get(null);
|
||||
|
||||
} catch (NoSuchFieldException |IllegalAccessException ex) {
|
||||
throw new InternalError("Unsafe.theUnsafe field not available", ex);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
private static JavaCorbaAccess javaCorbaAccess;
|
||||
|
||||
public static JavaCorbaAccess getJavaCorbaAccess() {
|
||||
if (javaCorbaAccess == null) {
|
||||
|
||||
@ -543,3 +543,4 @@ dfcbf839e299e7e2bba1da69bdb347617ea4c7e8 jdk-9+137
|
||||
fc0956308c7a586267c5dd35dff74f773aa9c3eb jdk-9+138
|
||||
08492e67bf3226784dab3bf9ae967382ddbc1af5 jdk-9+139
|
||||
fec31089c2ef5a12dd64f401b0bf2e00f56ee0d0 jdk-9+140
|
||||
160a00bc6ed0af1fdf8418fc65e6bddbbc0c536d jdk-9+141
|
||||
|
||||
@ -1894,6 +1894,22 @@ void LIR_Assembler::emit_arraycopy(LIR_OpArrayCopy* op) {
|
||||
__ beq(combined_check, slow);
|
||||
}
|
||||
|
||||
if (flags & LIR_OpArrayCopy::type_check) {
|
||||
if (!(flags & LIR_OpArrayCopy::LIR_OpArrayCopy::dst_objarray)) {
|
||||
__ load_klass(tmp, dst);
|
||||
__ lwz(tmp2, in_bytes(Klass::layout_helper_offset()), tmp);
|
||||
__ cmpwi(CCR0, tmp2, Klass::_lh_neutral_value);
|
||||
__ bge(CCR0, slow);
|
||||
}
|
||||
|
||||
if (!(flags & LIR_OpArrayCopy::LIR_OpArrayCopy::src_objarray)) {
|
||||
__ load_klass(tmp, src);
|
||||
__ lwz(tmp2, in_bytes(Klass::layout_helper_offset()), tmp);
|
||||
__ cmpwi(CCR0, tmp2, Klass::_lh_neutral_value);
|
||||
__ bge(CCR0, slow);
|
||||
}
|
||||
}
|
||||
|
||||
// Higher 32bits must be null.
|
||||
__ extsw(length, length);
|
||||
|
||||
|
||||
@ -2034,6 +2034,27 @@ void LIR_Assembler::emit_arraycopy(LIR_OpArrayCopy* op) {
|
||||
__ delayed()->nop();
|
||||
}
|
||||
|
||||
// If the compiler was not able to prove that exact type of the source or the destination
|
||||
// of the arraycopy is an array type, check at runtime if the source or the destination is
|
||||
// an instance type.
|
||||
if (flags & LIR_OpArrayCopy::type_check) {
|
||||
if (!(flags & LIR_OpArrayCopy::LIR_OpArrayCopy::dst_objarray)) {
|
||||
__ load_klass(dst, tmp);
|
||||
__ lduw(tmp, in_bytes(Klass::layout_helper_offset()), tmp2);
|
||||
__ cmp(tmp2, Klass::_lh_neutral_value);
|
||||
__ br(Assembler::greaterEqual, false, Assembler::pn, *stub->entry());
|
||||
__ delayed()->nop();
|
||||
}
|
||||
|
||||
if (!(flags & LIR_OpArrayCopy::LIR_OpArrayCopy::src_objarray)) {
|
||||
__ load_klass(src, tmp);
|
||||
__ lduw(tmp, in_bytes(Klass::layout_helper_offset()), tmp2);
|
||||
__ cmp(tmp2, Klass::_lh_neutral_value);
|
||||
__ br(Assembler::greaterEqual, false, Assembler::pn, *stub->entry());
|
||||
__ delayed()->nop();
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & LIR_OpArrayCopy::src_pos_positive_check) {
|
||||
// test src_pos register
|
||||
__ cmp_zero_and_br(Assembler::less, src_pos, *stub->entry());
|
||||
|
||||
@ -3146,6 +3146,23 @@ void LIR_Assembler::emit_arraycopy(LIR_OpArrayCopy* op) {
|
||||
__ jcc(Assembler::zero, *stub->entry());
|
||||
}
|
||||
|
||||
// If the compiler was not able to prove that exact type of the source or the destination
|
||||
// of the arraycopy is an array type, check at runtime if the source or the destination is
|
||||
// an instance type.
|
||||
if (flags & LIR_OpArrayCopy::type_check) {
|
||||
if (!(flags & LIR_OpArrayCopy::dst_objarray)) {
|
||||
__ load_klass(tmp, dst);
|
||||
__ cmpl(Address(tmp, in_bytes(Klass::layout_helper_offset())), Klass::_lh_neutral_value);
|
||||
__ jcc(Assembler::greaterEqual, *stub->entry());
|
||||
}
|
||||
|
||||
if (!(flags & LIR_OpArrayCopy::src_objarray)) {
|
||||
__ load_klass(tmp, src);
|
||||
__ cmpl(Address(tmp, in_bytes(Klass::layout_helper_offset())), Klass::_lh_neutral_value);
|
||||
__ jcc(Assembler::greaterEqual, *stub->entry());
|
||||
}
|
||||
}
|
||||
|
||||
// check if negative
|
||||
if (flags & LIR_OpArrayCopy::src_pos_positive_check) {
|
||||
__ testl(src_pos, src_pos);
|
||||
|
||||
@ -5859,6 +5859,11 @@ void ClassFileParser::post_process_parsed_stream(const ClassFileStream* const st
|
||||
assert(cp != NULL, "invariant");
|
||||
assert(_loader_data != NULL, "invariant");
|
||||
|
||||
if (_class_name == vmSymbols::java_lang_Object()) {
|
||||
check_property(_local_interfaces == Universe::the_empty_klass_array(),
|
||||
"java.lang.Object cannot implement an interface in class file %s",
|
||||
CHECK);
|
||||
}
|
||||
// We check super class after class file is parsed and format is checked
|
||||
if (_super_class_index > 0 && NULL ==_super_klass) {
|
||||
Symbol* const super_class_name = cp->klass_name_at(_super_class_index);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2010, 2016, 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
|
||||
@ -203,6 +203,7 @@ class stack_map_frame {
|
||||
inline bool verify(address start, address end) const;
|
||||
|
||||
inline void print_on(outputStream* st, int current_offset) const;
|
||||
inline void print_truncated(outputStream* st, int current_offset) const;
|
||||
|
||||
// Create as_xxx and is_xxx methods for the subtypes
|
||||
#define FRAME_TYPE_DECL(stackmap_frame_type, arg1, arg2) \
|
||||
@ -263,6 +264,10 @@ class same_frame : public stack_map_frame {
|
||||
void print_on(outputStream* st, int current_offset = -1) const {
|
||||
st->print("same_frame(@%d)", offset_delta() + current_offset);
|
||||
}
|
||||
|
||||
void print_truncated(outputStream* st, int current_offset = -1) const {
|
||||
print_on(st, current_offset);
|
||||
}
|
||||
};
|
||||
|
||||
class same_frame_extended : public stack_map_frame {
|
||||
@ -309,6 +314,10 @@ class same_frame_extended : public stack_map_frame {
|
||||
void print_on(outputStream* st, int current_offset = -1) const {
|
||||
st->print("same_frame_extended(@%d)", offset_delta() + current_offset);
|
||||
}
|
||||
|
||||
void print_truncated(outputStream* st, int current_offset = -1) const {
|
||||
print_on(st, current_offset);
|
||||
}
|
||||
};
|
||||
|
||||
class same_locals_1_stack_item_frame : public stack_map_frame {
|
||||
@ -381,6 +390,11 @@ class same_locals_1_stack_item_frame : public stack_map_frame {
|
||||
types()->print_on(st);
|
||||
st->print(")");
|
||||
}
|
||||
|
||||
void print_truncated(outputStream* st, int current_offset = -1) const {
|
||||
st->print("same_locals_1_stack_item_frame(@%d), output truncated, Stackmap exceeds table size.",
|
||||
offset_delta() + current_offset);
|
||||
}
|
||||
};
|
||||
|
||||
class same_locals_1_stack_item_extended : public stack_map_frame {
|
||||
@ -446,6 +460,11 @@ class same_locals_1_stack_item_extended : public stack_map_frame {
|
||||
types()->print_on(st);
|
||||
st->print(")");
|
||||
}
|
||||
|
||||
void print_truncated(outputStream* st, int current_offset = -1) const {
|
||||
st->print("same_locals_1_stack_item_extended(@%d), output truncated, Stackmap exceeds table size.",
|
||||
offset_delta() + current_offset);
|
||||
}
|
||||
};
|
||||
|
||||
class chop_frame : public stack_map_frame {
|
||||
@ -511,6 +530,10 @@ class chop_frame : public stack_map_frame {
|
||||
void print_on(outputStream* st, int current_offset = -1) const {
|
||||
st->print("chop_frame(@%d,%d)", offset_delta() + current_offset, chops());
|
||||
}
|
||||
|
||||
void print_truncated(outputStream* st, int current_offset = -1) const {
|
||||
print_on(st, current_offset);
|
||||
}
|
||||
};
|
||||
|
||||
class append_frame : public stack_map_frame {
|
||||
@ -619,6 +642,11 @@ class append_frame : public stack_map_frame {
|
||||
}
|
||||
st->print(")");
|
||||
}
|
||||
|
||||
void print_truncated(outputStream* st, int current_offset = -1) const {
|
||||
st->print("append_frame(@%d), output truncated, Stackmap exceeds table size.",
|
||||
offset_delta() + current_offset);
|
||||
}
|
||||
};
|
||||
|
||||
class full_frame : public stack_map_frame {
|
||||
@ -784,6 +812,11 @@ class full_frame : public stack_map_frame {
|
||||
}
|
||||
st->print("})");
|
||||
}
|
||||
|
||||
void print_truncated(outputStream* st, int current_offset = -1) const {
|
||||
st->print("full_frame(@%d), output truncated, Stackmap exceeds table size.",
|
||||
offset_delta() + current_offset);
|
||||
}
|
||||
};
|
||||
|
||||
#define VIRTUAL_DISPATCH(stack_frame_type, func_name, args) \
|
||||
@ -841,6 +874,10 @@ void stack_map_frame::print_on(outputStream* st, int offs = -1) const {
|
||||
FOR_EACH_STACKMAP_FRAME_TYPE(VOID_VIRTUAL_DISPATCH, print_on, (st, offs));
|
||||
}
|
||||
|
||||
void stack_map_frame::print_truncated(outputStream* st, int offs = -1) const {
|
||||
FOR_EACH_STACKMAP_FRAME_TYPE(VOID_VIRTUAL_DISPATCH, print_truncated, (st, offs));
|
||||
}
|
||||
|
||||
#undef VIRTUAL_DISPATCH
|
||||
#undef VOID_VIRTUAL_DISPATCH
|
||||
|
||||
|
||||
@ -541,8 +541,19 @@ void ErrorContext::stackmap_details(outputStream* ss, const Method* method) cons
|
||||
stack_map_frame* sm_frame = sm_table->entries();
|
||||
streamIndentor si2(ss);
|
||||
int current_offset = -1;
|
||||
// Subtract two from StackMapAttribute length because the length includes
|
||||
// two bytes for number of table entries.
|
||||
size_t sm_table_space = method->stackmap_data()->length() - 2;
|
||||
for (u2 i = 0; i < sm_table->number_of_entries(); ++i) {
|
||||
ss->indent();
|
||||
size_t sm_frame_size = sm_frame->size();
|
||||
// If the size of the next stackmap exceeds the length of the entire
|
||||
// stackmap table then print a truncated message and return.
|
||||
if (sm_frame_size > sm_table_space) {
|
||||
sm_frame->print_truncated(ss, current_offset);
|
||||
return;
|
||||
}
|
||||
sm_table_space -= sm_frame_size;
|
||||
sm_frame->print_on(ss, current_offset);
|
||||
ss->cr();
|
||||
current_offset += sm_frame->offset_delta();
|
||||
|
||||
@ -2524,7 +2524,6 @@ JVM_ENTRY(const char*, JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_i
|
||||
switch (cp->tag_at(cp_index).value()) {
|
||||
case JVM_CONSTANT_InterfaceMethodref:
|
||||
case JVM_CONSTANT_Methodref:
|
||||
case JVM_CONSTANT_NameAndType: // for invokedynamic
|
||||
return cp->uncached_name_ref_at(cp_index)->as_utf8();
|
||||
default:
|
||||
fatal("JVM_GetCPMethodNameUTF: illegal constant");
|
||||
@ -2542,7 +2541,6 @@ JVM_ENTRY(const char*, JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint
|
||||
switch (cp->tag_at(cp_index).value()) {
|
||||
case JVM_CONSTANT_InterfaceMethodref:
|
||||
case JVM_CONSTANT_Methodref:
|
||||
case JVM_CONSTANT_NameAndType: // for invokedynamic
|
||||
return cp->uncached_signature_ref_at(cp_index)->as_utf8();
|
||||
default:
|
||||
fatal("JVM_GetCPMethodSignatureUTF: illegal constant");
|
||||
|
||||
@ -794,9 +794,10 @@ static bool append_to_string_flag(const char* name, const char* new_value, Flag:
|
||||
} else if (new_len == 0) {
|
||||
value = old_value;
|
||||
} else {
|
||||
char* buf = NEW_C_HEAP_ARRAY(char, old_len + 1 + new_len + 1, mtArguments);
|
||||
size_t length = old_len + 1 + new_len + 1;
|
||||
char* buf = NEW_C_HEAP_ARRAY(char, length, mtArguments);
|
||||
// each new setting adds another LINE to the switch:
|
||||
sprintf(buf, "%s\n%s", old_value, new_value);
|
||||
jio_snprintf(buf, length, "%s\n%s", old_value, new_value);
|
||||
value = buf;
|
||||
free_this_too = buf;
|
||||
}
|
||||
@ -1014,15 +1015,17 @@ const char* Arguments::build_resource_string(char** args, int count) {
|
||||
if (args == NULL || count == 0) {
|
||||
return NULL;
|
||||
}
|
||||
size_t length = strlen(args[0]) + 1; // add 1 for the null terminator
|
||||
for (int i = 1; i < count; i++) {
|
||||
length += strlen(args[i]) + 1; // add 1 for a space
|
||||
size_t length = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
length += strlen(args[i]) + 1; // add 1 for a space or NULL terminating character
|
||||
}
|
||||
char* s = NEW_RESOURCE_ARRAY(char, length);
|
||||
strcpy(s, args[0]);
|
||||
for (int j = 1; j < count; j++) {
|
||||
strcat(s, " ");
|
||||
strcat(s, args[j]);
|
||||
char* dst = s;
|
||||
for (int j = 0; j < count; j++) {
|
||||
size_t offset = strlen(args[j]) + 1; // add 1 for a space or NULL terminating character
|
||||
jio_snprintf(dst, length, "%s ", args[j]); // jio_snprintf will replace the last space character with NULL character
|
||||
dst += offset;
|
||||
length -= offset;
|
||||
}
|
||||
return (const char*) s;
|
||||
}
|
||||
@ -1106,9 +1109,8 @@ bool Arguments::process_argument(const char* arg,
|
||||
// Only make the obsolete check for valid arguments.
|
||||
if (arg_len <= BUFLEN) {
|
||||
// Construct a string which consists only of the argument name without '+', '-', or '='.
|
||||
char stripped_argname[BUFLEN+1];
|
||||
strncpy(stripped_argname, argname, arg_len);
|
||||
stripped_argname[arg_len] = '\0'; // strncpy may not null terminate.
|
||||
char stripped_argname[BUFLEN+1]; // +1 for '\0'
|
||||
jio_snprintf(stripped_argname, arg_len+1, "%s", argname); // +1 for '\0'
|
||||
if (is_obsolete_flag(stripped_argname, &since)) {
|
||||
char version[256];
|
||||
since.to_string(version, sizeof(version));
|
||||
@ -1260,8 +1262,7 @@ bool Arguments::add_property(const char* prop, PropertyWriteable writeable, Prop
|
||||
size_t key_len = eq - prop;
|
||||
char* tmp_key = AllocateHeap(key_len + 1, mtArguments);
|
||||
|
||||
strncpy(tmp_key, prop, key_len);
|
||||
tmp_key[key_len] = '\0';
|
||||
jio_snprintf(tmp_key, key_len + 1, "%s", prop);
|
||||
key = tmp_key;
|
||||
|
||||
value = &prop[key_len + 1];
|
||||
@ -2256,7 +2257,7 @@ jint Arguments::set_aggressive_opts_flags() {
|
||||
|
||||
// Feed the cache size setting into the JDK
|
||||
char buffer[1024];
|
||||
sprintf(buffer, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax);
|
||||
jio_snprintf(buffer, 1024, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax);
|
||||
if (!add_property(buffer)) {
|
||||
return JNI_ENOMEM;
|
||||
}
|
||||
@ -2777,8 +2778,8 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
|
||||
if (tail != NULL) {
|
||||
const char* pos = strchr(tail, ':');
|
||||
size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
|
||||
char* name = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len + 1, mtArguments), tail, len);
|
||||
name[len] = '\0';
|
||||
char* name = NEW_C_HEAP_ARRAY(char, len + 1, mtArguments);
|
||||
jio_snprintf(name, len + 1, "%s", tail);
|
||||
|
||||
char *options = NULL;
|
||||
if(pos != NULL) {
|
||||
@ -2854,7 +2855,9 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
|
||||
return JNI_ERR;
|
||||
#else
|
||||
if (tail != NULL) {
|
||||
char *options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(tail) + 1, mtArguments), tail);
|
||||
size_t length = strlen(tail) + 1;
|
||||
char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
|
||||
jio_snprintf(options, length, "%s", tail);
|
||||
add_init_agent("instrument", options, false);
|
||||
// java agents need module java.instrument
|
||||
if (!create_numbered_property("jdk.module.addmods", "java.instrument", addmods_count++)) {
|
||||
@ -3512,7 +3515,7 @@ jint Arguments::finalize_vm_init_args() {
|
||||
// check if the default lib/endorsed directory exists; if so, error
|
||||
char path[JVM_MAXPATHLEN];
|
||||
const char* fileSep = os::file_separator();
|
||||
sprintf(path, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep);
|
||||
jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep);
|
||||
|
||||
if (CheckEndorsedAndExtDirs) {
|
||||
int nonEmptyDirs = 0;
|
||||
@ -3534,7 +3537,7 @@ jint Arguments::finalize_vm_init_args() {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
sprintf(path, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep);
|
||||
jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep);
|
||||
dir = os::opendir(path);
|
||||
if (dir != NULL) {
|
||||
jio_fprintf(defaultStream::output_stream(),
|
||||
@ -3899,6 +3902,13 @@ jint Arguments::parse_options_buffer(const char* name, char* buffer, const size_
|
||||
|
||||
void Arguments::set_shared_spaces_flags() {
|
||||
if (DumpSharedSpaces) {
|
||||
if (FailOverToOldVerifier) {
|
||||
// Don't fall back to the old verifier on verification failure. If a
|
||||
// class fails verification with the split verifier, it might fail the
|
||||
// CDS runtime verifier constraint check. In that case, we don't want
|
||||
// to share the class. We only archive classes that pass the split verifier.
|
||||
FLAG_SET_DEFAULT(FailOverToOldVerifier, false);
|
||||
}
|
||||
|
||||
if (RequireSharedSpaces) {
|
||||
warning("Cannot dump shared archive while using shared archive");
|
||||
|
||||
@ -2881,8 +2881,6 @@ VMRegPair *SharedRuntime::find_callee_arguments(Symbol* sig, bool has_receiver,
|
||||
char *s = sig->as_C_string();
|
||||
int len = (int)strlen(s);
|
||||
s++; len--; // Skip opening paren
|
||||
char *t = s+len;
|
||||
while (*(--t) != ')'); // Find close paren
|
||||
|
||||
BasicType *sig_bt = NEW_RESOURCE_ARRAY(BasicType, 256);
|
||||
VMRegPair *regs = NEW_RESOURCE_ARRAY(VMRegPair, 256);
|
||||
@ -2891,7 +2889,7 @@ VMRegPair *SharedRuntime::find_callee_arguments(Symbol* sig, bool has_receiver,
|
||||
sig_bt[cnt++] = T_OBJECT; // Receiver is argument 0; not in signature
|
||||
}
|
||||
|
||||
while (s < t) {
|
||||
while (*s != ')') { // Find closing right paren
|
||||
switch (*s++) { // Switch on signature character
|
||||
case 'B': sig_bt[cnt++] = T_BYTE; break;
|
||||
case 'C': sig_bt[cnt++] = T_CHAR; break;
|
||||
|
||||
@ -224,7 +224,49 @@ void SignatureIterator::iterate_returntype() {
|
||||
_index = 0;
|
||||
expect('(');
|
||||
Symbol* sig = _signature;
|
||||
while (sig->byte_at(_index) != ')') _index++;
|
||||
// Need to skip over each type in the signature's argument list until a
|
||||
// closing ')' is found., then get the return type. We cannot just scan
|
||||
// for the first ')' because ')' is a legal character in a type name.
|
||||
while (sig->byte_at(_index) != ')') {
|
||||
switch(sig->byte_at(_index)) {
|
||||
case 'B':
|
||||
case 'C':
|
||||
case 'D':
|
||||
case 'F':
|
||||
case 'I':
|
||||
case 'J':
|
||||
case 'S':
|
||||
case 'Z':
|
||||
case 'V':
|
||||
{
|
||||
_index++;
|
||||
}
|
||||
break;
|
||||
case 'L':
|
||||
{
|
||||
while (sig->byte_at(_index++) != ';') ;
|
||||
}
|
||||
break;
|
||||
case '[':
|
||||
{
|
||||
int begin = ++_index;
|
||||
skip_optional_size();
|
||||
while (sig->byte_at(_index) == '[') {
|
||||
_index++;
|
||||
skip_optional_size();
|
||||
}
|
||||
if (sig->byte_at(_index) == 'L') {
|
||||
while (sig->byte_at(_index++) != ';') ;
|
||||
} else {
|
||||
_index++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ShouldNotReachHere();
|
||||
break;
|
||||
}
|
||||
}
|
||||
expect(')');
|
||||
// Parse return type
|
||||
_parameter_index = -1;
|
||||
|
||||
64
hotspot/test/compiler/c1/TestArrayCopyToFromObject.java
Normal file
64
hotspot/test/compiler/c1/TestArrayCopyToFromObject.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8160591
|
||||
* @summary C1-generated code for System.arraycopy() does not throw an ArrayStoreException if 'dst' is no a "proper" array (i.e., it is java.lang.Object)
|
||||
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xcomp -XX:-UseCompressedClassPointers -XX:CompileOnly=TestArrayCopyToFromObject.test TestArrayCopyToFromObject
|
||||
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xcomp -XX:+UseCompressedClassPointers -XX:CompileOnly=TestArrayCopyToFromObject.test TestArrayCopyToFromObject
|
||||
*/
|
||||
public class TestArrayCopyToFromObject {
|
||||
|
||||
public void test(Object aArray[]) {
|
||||
Object a = new Object();
|
||||
|
||||
try {
|
||||
System.arraycopy(aArray, 0, a, 0, 1);
|
||||
throw new RuntimeException ("FAILED: Expected ArrayStoreException " +
|
||||
"(due to destination not being an array) " +
|
||||
"was not thrown");
|
||||
} catch (ArrayStoreException e) {
|
||||
System.out.println("PASSED: Expected ArrayStoreException was thrown");
|
||||
}
|
||||
|
||||
try {
|
||||
System.arraycopy(a, 0, aArray, 0, 1);
|
||||
throw new RuntimeException ("FAILED: Expected ArrayStoreException " +
|
||||
"(due to source not being an array) " +
|
||||
"was not thrown");
|
||||
} catch (ArrayStoreException e) {
|
||||
System.out.println("PASSED: Expected ArrayStoreException was thrown");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println("TestArrayCopyToFromObject");
|
||||
Object aArray[] = new Object[10];
|
||||
for (int i = 0; i < 10; i++) {
|
||||
aArray[i] = new Object();
|
||||
}
|
||||
new TestArrayCopyToFromObject().test(aArray);
|
||||
}
|
||||
}
|
||||
@ -383,3 +383,4 @@ a8d5fe567ae72b4931040e59dd4478363f9004f5 jdk-9+137
|
||||
69c3b12ba75b2e321dee731ac545e7fbff608451 jdk-9+138
|
||||
8991d71c5316bde259e6a417c1199b008ca3cdf0 jdk-9+139
|
||||
8d100cb9b04819b5bd09f33c7fd5b8628d1a456f jdk-9+140
|
||||
037c095ba0c345edbeaaab52fda913a76c3930c0 jdk-9+141
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
@ -31,6 +31,7 @@ import com.sun.org.apache.bcel.internal.generic.GETFIELD;
|
||||
import com.sun.org.apache.bcel.internal.generic.GETSTATIC;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.ISTORE;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
|
||||
@ -1252,6 +1253,10 @@ public final class Stylesheet extends SyntaxTreeNode {
|
||||
classGen.getConstantPool());
|
||||
transf.addException("com.sun.org.apache.xalan.internal.xsltc.TransletException");
|
||||
|
||||
// call resetPrefixIndex at the beginning of transform
|
||||
final int check = cpg.addMethodref(BASIS_LIBRARY_CLASS, "resetPrefixIndex", "()V");
|
||||
il.append(new INVOKESTATIC(check));
|
||||
|
||||
// Define and initialize current with the root node
|
||||
final LocalVariableGen current =
|
||||
transf.addLocalVariable("current",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
@ -31,6 +31,7 @@ import java.text.MessageFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.xsltc.DOM;
|
||||
@ -1533,16 +1534,25 @@ public final class BasisLibrary {
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is used in the execution of xsl:element
|
||||
* These functions are used in the execution of xsl:element to generate
|
||||
* and reset namespace prefix index local to current transformation process
|
||||
*/
|
||||
private static int prefixIndex = 0;
|
||||
|
||||
public static String generatePrefix() {
|
||||
synchronized (BasisLibrary.class) {
|
||||
return ("ns" + prefixIndex++);
|
||||
}
|
||||
return ("ns" + threadLocalPrefixIndex.get().getAndIncrement());
|
||||
}
|
||||
|
||||
public static void resetPrefixIndex() {
|
||||
threadLocalPrefixIndex.get().set(0);
|
||||
}
|
||||
|
||||
private static final ThreadLocal<AtomicInteger> threadLocalPrefixIndex =
|
||||
new ThreadLocal<AtomicInteger>() {
|
||||
@Override
|
||||
protected AtomicInteger initialValue() {
|
||||
return new AtomicInteger();
|
||||
}
|
||||
};
|
||||
|
||||
public static final String RUN_TIME_INTERNAL_ERR =
|
||||
"RUN_TIME_INTERNAL_ERR";
|
||||
public static final String RUN_TIME_COPY_ERR =
|
||||
|
||||
@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package transform;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Templates;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static jaxp.library.JAXPTestUtilities.runWithAllPerm;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8167179
|
||||
* @library /javax/xml/jaxp/libs
|
||||
* @run testng/othervm -DrunSecMngr=true transform.NamespacePrefixTest
|
||||
* @run testng/othervm transform.NamespacePrefixTest
|
||||
* @summary This class tests the generation of namespace prefixes
|
||||
*/
|
||||
public class NamespacePrefixTest {
|
||||
|
||||
@Test
|
||||
public void testReuseTemplates() throws Exception {
|
||||
final TransformerFactory tf = TransformerFactory.newInstance();
|
||||
final Source xslsrc = new StreamSource(new StringReader(XSL));
|
||||
final Templates tmpl = tf.newTemplates(xslsrc);
|
||||
for (int i = 0; i < TRANSF_COUNT; i++) {
|
||||
checkResult(doTransformation(tmpl.newTransformer()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReuseTransformer() throws Exception {
|
||||
final TransformerFactory tf = TransformerFactory.newInstance();
|
||||
final Source xslsrc = new StreamSource(new StringReader(XSL));
|
||||
final Transformer t = tf.newTransformer(xslsrc);
|
||||
for (int i = 0; i < TRANSF_COUNT; i++) {
|
||||
checkResult(doTransformation(t));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConcurrentTransformations() throws Exception {
|
||||
final TransformerFactory tf = TransformerFactory.newInstance();
|
||||
final Source xslsrc = new StreamSource(new StringReader(XSL));
|
||||
final Templates tmpl = tf.newTemplates(xslsrc);
|
||||
concurrentTestPassed.set(true);
|
||||
|
||||
// Execute multiple TestWorker tasks
|
||||
for (int id = 0; id < THREADS_COUNT; id++) {
|
||||
EXECUTOR.execute(new TransformerThread(tmpl.newTransformer(), id));
|
||||
}
|
||||
// Initiate shutdown of previously submitted task
|
||||
runWithAllPerm(EXECUTOR::shutdown);
|
||||
// Wait for termination of submitted tasks
|
||||
if (!EXECUTOR.awaitTermination(THREADS_COUNT, TimeUnit.SECONDS)) {
|
||||
// If not all tasks terminates during the time out force them to shutdown
|
||||
runWithAllPerm(EXECUTOR::shutdownNow);
|
||||
}
|
||||
// Check if all transformation threads generated the correct namespace prefix
|
||||
assertTrue(concurrentTestPassed.get());
|
||||
}
|
||||
|
||||
// Do one transformation with the provided transformer
|
||||
private static String doTransformation(Transformer t) throws Exception {
|
||||
StringWriter resWriter = new StringWriter();
|
||||
Source xmlSrc = new StreamSource(new StringReader(XML));
|
||||
t.transform(xmlSrc, new StreamResult(resWriter));
|
||||
return resWriter.toString();
|
||||
}
|
||||
|
||||
// Check if the transformation result string contains the
|
||||
// element with the exact namespace prefix generated.
|
||||
private static void checkResult(String result) {
|
||||
// Check prefix of 'Element2' element, it should always be the same
|
||||
assertTrue(result.contains(EXPECTED_CONTENT));
|
||||
}
|
||||
|
||||
// Check if the transformation result string contains the element with
|
||||
// the exact namespace prefix generated by current thread.
|
||||
// If the expected prefix is not found and there was no failures observed by
|
||||
// other test threads then mark concurrent test as failed.
|
||||
private static void checkThreadResult(String result, int id) {
|
||||
boolean res = result.contains(EXPECTED_CONTENT);
|
||||
System.out.printf("%d: transformation result: %s%n", id, res ? "Pass" : "Fail");
|
||||
if (!res) {
|
||||
System.out.printf("%d result:%s%n", id, result);
|
||||
}
|
||||
concurrentTestPassed.compareAndSet(true, res);
|
||||
}
|
||||
|
||||
// TransformerThread task that does the transformation similar
|
||||
// to testReuseTransformer test method
|
||||
private class TransformerThread implements Runnable {
|
||||
|
||||
private final Transformer transformer;
|
||||
private final int id;
|
||||
|
||||
TransformerThread(Transformer transformer, int id) {
|
||||
this.transformer = transformer;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
System.out.printf("%d: waiting for barrier%n", id);
|
||||
//Synchronize startup of all tasks
|
||||
BARRIER.await();
|
||||
System.out.printf("%d: starting transformation%n", id);
|
||||
checkThreadResult(doTransformation(transformer), id);
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("TransformerThread " + id + " failed", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Number of subsequent transformations
|
||||
private static final int TRANSF_COUNT = 10;
|
||||
|
||||
// Number of transformer threads running concurently
|
||||
private static final int THREADS_COUNT = 10;
|
||||
|
||||
// Variable for storing the concurrent transformation test result. It is
|
||||
// updated by transformer threads
|
||||
private static final AtomicBoolean concurrentTestPassed = new AtomicBoolean(true);
|
||||
|
||||
// Cyclic barrier for threads startup synchronization
|
||||
private static final CyclicBarrier BARRIER = new CyclicBarrier(THREADS_COUNT);
|
||||
|
||||
// Thread pool
|
||||
private static final ExecutorService EXECUTOR = Executors.newCachedThreadPool();
|
||||
|
||||
// XSL that transforms XML and produces unique namespace prefixes for each element
|
||||
private final static String XSL = "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n"
|
||||
+ " <xsl:template match=\"node()|@*\" priority=\"1\">\n"
|
||||
+ " <xsl:copy>\n"
|
||||
+ " <xsl:apply-templates select=\"node()|@*\"/>\n"
|
||||
+ " </xsl:copy>\n"
|
||||
+ " </xsl:template>\n"
|
||||
+ " <xsl:template match=\"*\" priority=\"2\">\n"
|
||||
+ " <xsl:element name=\"{name()}\" namespace=\"{namespace-uri()}\">\n"
|
||||
+ " <xsl:apply-templates select=\"node()|@*\"/>\n"
|
||||
+ " </xsl:element>\n"
|
||||
+ " </xsl:template>\n"
|
||||
+ "</xsl:stylesheet>";
|
||||
|
||||
// Simple XML content with root and two child elements
|
||||
private final static String XML = "<TestRoot xmlns=\"test.xmlns\">\n"
|
||||
+ " <Element1 xmlns=\"test.xmlns\">\n"
|
||||
+ " </Element1>\n"
|
||||
+ " <Element2 xmlns=\"test.xmlns\">\n"
|
||||
+ " </Element2>\n"
|
||||
+ "</TestRoot>";
|
||||
|
||||
// With thread local namespace prefix index each transformation result should
|
||||
// be the same and contain the same prefix for Element2
|
||||
private final static String EXPECTED_CONTENT = "</ns2:Element2>";
|
||||
|
||||
}
|
||||
@ -386,3 +386,4 @@ ab1d78d395d4cb8be426ff181211da1a4085cf01 jdk-9+134
|
||||
7d3a8f52b124db26ba8425c2931b748dd9d2791b jdk-9+138
|
||||
7a7aadf3c4500cc273c889aa1172d4fe3844bb6b jdk-9+139
|
||||
9004617323fe99cbe4fad48f373cb2ed4fc50aa6 jdk-9+140
|
||||
b2c18f755228d1d19a86cd7d5fa1abb6b1495dfb jdk-9+141
|
||||
|
||||
@ -383,3 +383,4 @@ e72df94364e3686e7d62059ce0d6b187b82da713 jdk-9+137
|
||||
665096863382bf23ce891307cf2a7511e77c1c88 jdk-9+138
|
||||
5518ac2f2ead5e594bd983f2047178136aafdfd0 jdk-9+139
|
||||
e93b7ea559759f036c9f69fd2ddaf47bb4e98385 jdk-9+140
|
||||
8d752af5f61d41f226adf2cda72a20faa9ad620a jdk-9+141
|
||||
|
||||
@ -55,7 +55,6 @@ $(eval $(call SetupJavaCompilation,BUILD_BREAKITERATOR_BASE, \
|
||||
$(eval $(call SetupJavaCompilation,BUILD_BREAKITERATOR_LD, \
|
||||
SETUP := GENERATE_OLDBYTECODE, \
|
||||
SRC := $(JDK_TOPDIR)/src/jdk.localedata/share/classes, \
|
||||
INCLUDES := $(TEXT_PKG_LD), \
|
||||
INCLUDE_FILES := \
|
||||
$(TEXT_PKG_LD)/BreakIteratorRules_th.java \
|
||||
$(TEXT_PKG_LD)/BreakIteratorInfo_th.java, \
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2016, 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,7 +26,6 @@
|
||||
package java.io;
|
||||
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import sun.nio.ch.FileChannelImpl;
|
||||
|
||||
|
||||
@ -60,7 +59,9 @@ class FileInputStream extends InputStream
|
||||
|
||||
private volatile FileChannel channel;
|
||||
|
||||
private final AtomicBoolean closed = new AtomicBoolean(false);
|
||||
private final Object closeLock = new Object();
|
||||
|
||||
private volatile boolean closed;
|
||||
|
||||
/**
|
||||
* Creates a <code>FileInputStream</code> by
|
||||
@ -313,14 +314,21 @@ class FileInputStream extends InputStream
|
||||
* @spec JSR-51
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
if (!closed.compareAndSet(false, true)) {
|
||||
// if compareAndSet() returns false closed was already true
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
synchronized (closeLock) {
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
closed = true;
|
||||
}
|
||||
|
||||
FileChannel fc = channel;
|
||||
if (fc != null) {
|
||||
fc.close();
|
||||
// possible race with getChannel(), benign since
|
||||
// FileChannel.close is final and idempotent
|
||||
fc.close();
|
||||
}
|
||||
|
||||
fd.closeAll(new Closeable() {
|
||||
@ -370,8 +378,10 @@ class FileInputStream extends InputStream
|
||||
fc = this.channel;
|
||||
if (fc == null) {
|
||||
this.channel = fc = FileChannelImpl.open(fd, path, true, false, this);
|
||||
if (closed.get()) {
|
||||
if (closed) {
|
||||
try {
|
||||
// possible race with close(), benign since
|
||||
// FileChannel.close is final and idempotent
|
||||
fc.close();
|
||||
} catch (IOException ioe) {
|
||||
throw new InternalError(ioe); // should not happen
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2016, 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,7 +26,6 @@
|
||||
package java.io;
|
||||
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
import jdk.internal.misc.JavaIOFileDescriptorAccess;
|
||||
import sun.nio.ch.FileChannelImpl;
|
||||
@ -77,7 +76,9 @@ class FileOutputStream extends OutputStream
|
||||
*/
|
||||
private final String path;
|
||||
|
||||
private final AtomicBoolean closed = new AtomicBoolean(false);
|
||||
private final Object closeLock = new Object();
|
||||
|
||||
private volatile boolean closed;
|
||||
|
||||
/**
|
||||
* Creates a file output stream to write to the file with the
|
||||
@ -341,14 +342,21 @@ class FileOutputStream extends OutputStream
|
||||
* @spec JSR-51
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
if (!closed.compareAndSet(false, true)) {
|
||||
// if compareAndSet() returns false closed was already true
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
synchronized (closeLock) {
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
closed = true;
|
||||
}
|
||||
|
||||
FileChannel fc = channel;
|
||||
if (fc != null) {
|
||||
fc.close();
|
||||
// possible race with getChannel(), benign since
|
||||
// FileChannel.close is final and idempotent
|
||||
fc.close();
|
||||
}
|
||||
|
||||
fd.closeAll(new Closeable() {
|
||||
@ -399,8 +407,10 @@ class FileOutputStream extends OutputStream
|
||||
fc = this.channel;
|
||||
if (fc == null) {
|
||||
this.channel = fc = FileChannelImpl.open(fd, path, false, true, this);
|
||||
if (closed.get()) {
|
||||
if (closed) {
|
||||
try {
|
||||
// possible race with close(), benign since
|
||||
// FileChannel.close is final and idempotent
|
||||
fc.close();
|
||||
} catch (IOException ioe) {
|
||||
throw new InternalError(ioe); // should not happen
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2016, 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
|
||||
@ -1413,27 +1413,7 @@ public class ObjectStreamClass implements Serializable {
|
||||
* returned constructor (if any).
|
||||
*/
|
||||
private static Constructor<?> getSerializableConstructor(Class<?> cl) {
|
||||
Class<?> initCl = cl;
|
||||
while (Serializable.class.isAssignableFrom(initCl)) {
|
||||
if ((initCl = initCl.getSuperclass()) == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
try {
|
||||
Constructor<?> cons = initCl.getDeclaredConstructor((Class<?>[]) null);
|
||||
int mods = cons.getModifiers();
|
||||
if ((mods & Modifier.PRIVATE) != 0 ||
|
||||
((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
|
||||
!packageEquals(cl, initCl)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
cons = reflFactory.newConstructorForSerialization(cl, cons);
|
||||
cons.setAccessible(true);
|
||||
return cons;
|
||||
} catch (NoSuchMethodException ex) {
|
||||
return null;
|
||||
}
|
||||
return reflFactory.newConstructorForSerialization(cl);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -104,9 +104,9 @@ import sun.security.util.SecurityConstants;
|
||||
* class or resource itself.
|
||||
*
|
||||
* <p> Class loaders that support concurrent loading of classes are known as
|
||||
* <em>parallel capable</em> class loaders and are required to register
|
||||
* themselves at their class initialization time by invoking the
|
||||
* {@link
|
||||
* <em>{@linkplain #isParallelCapable() parallel capable}</em> class loaders and
|
||||
* are required to register themselves at their class initialization time by
|
||||
* invoking the {@link
|
||||
* #registerAsParallelCapable <tt>ClassLoader.registerAsParallelCapable</tt>}
|
||||
* method. Note that the <tt>ClassLoader</tt> class is registered as parallel
|
||||
* capable by default. However, its subclasses still need to register themselves
|
||||
@ -1437,7 +1437,7 @@ public abstract class ClassLoader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the caller as parallel capable.
|
||||
* Registers the caller as {@linkplain #isParallelCapable() parallel capable}.
|
||||
* The registration succeeds if and only if all of the following
|
||||
* conditions are met:
|
||||
* <ol>
|
||||
@ -1448,8 +1448,10 @@ public abstract class ClassLoader {
|
||||
* <p>Note that once a class loader is registered as parallel capable, there
|
||||
* is no way to change it back.</p>
|
||||
*
|
||||
* @return true if the caller is successfully registered as
|
||||
* parallel capable and false if otherwise.
|
||||
* @return {@code true} if the caller is successfully registered as
|
||||
* parallel capable and {@code false} if otherwise.
|
||||
*
|
||||
* @see #isParallelCapable()
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@ -1460,6 +1462,22 @@ public abstract class ClassLoader {
|
||||
return ParallelLoaders.register(callerClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this class loader is
|
||||
* {@linkplain #registerAsParallelCapable parallel capable}, otherwise
|
||||
* {@code false}.
|
||||
*
|
||||
* @return {@code true} if this class loader is parallel capable,
|
||||
* otherwise {@code false}.
|
||||
*
|
||||
* @see #registerAsParallelCapable()
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public final boolean isParallelCapable() {
|
||||
return ParallelLoaders.isRegistered(this.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a resource of the specified name from the search path used to load
|
||||
* classes. This method locates the resource through the system class
|
||||
|
||||
@ -201,13 +201,13 @@ class InetAddress implements java.io.Serializable {
|
||||
* Specify the address family: Internet Protocol, Version 4
|
||||
* @since 1.4
|
||||
*/
|
||||
static final int IPv4 = 1;
|
||||
@Native static final int IPv4 = 1;
|
||||
|
||||
/**
|
||||
* Specify the address family: Internet Protocol, Version 6
|
||||
* @since 1.4
|
||||
*/
|
||||
static final int IPv6 = 2;
|
||||
@Native static final int IPv6 = 2;
|
||||
|
||||
/* Specify address family preference */
|
||||
static transient final int preferIPv6Address;
|
||||
@ -321,6 +321,13 @@ class InetAddress implements java.io.Serializable {
|
||||
public String getOriginalHostName(InetAddress ia) {
|
||||
return ia.holder.getOriginalHostName();
|
||||
}
|
||||
|
||||
public InetAddress getByName(String hostName,
|
||||
InetAddress hostAddress)
|
||||
throws UnknownHostException
|
||||
{
|
||||
return InetAddress.getByName(hostName, hostAddress);
|
||||
}
|
||||
}
|
||||
);
|
||||
init();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2016, 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
|
||||
@ -51,6 +51,8 @@ import java.util.jar.Manifest;
|
||||
|
||||
import jdk.internal.loader.Resource;
|
||||
import jdk.internal.loader.URLClassPath;
|
||||
import jdk.internal.misc.JavaNetURLClassLoaderAccess;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
import jdk.internal.perf.PerfCounter;
|
||||
import sun.net.www.ParseUtil;
|
||||
import sun.security.util.SecurityConstants;
|
||||
@ -765,6 +767,14 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
|
||||
}
|
||||
|
||||
static {
|
||||
SharedSecrets.setJavaNetURLClassLoaderAccess(
|
||||
new JavaNetURLClassLoaderAccess() {
|
||||
@Override
|
||||
public AccessControlContext getAccessControlContext(URLClassLoader u) {
|
||||
return u.acc;
|
||||
}
|
||||
}
|
||||
);
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,6 +89,11 @@ public class ProtectionDomain {
|
||||
AccessController.getContext(), context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtectionDomain[] getProtectDomains(AccessControlContext context) {
|
||||
return context.getContext();
|
||||
}
|
||||
|
||||
private static AccessControlContext getCombinedACC(
|
||||
AccessControlContext context, AccessControlContext stack) {
|
||||
AccessControlContext acc =
|
||||
|
||||
@ -368,7 +368,7 @@ public final class HijrahDate
|
||||
if (field instanceof ChronoField) {
|
||||
switch ((ChronoField) field) {
|
||||
case DAY_OF_WEEK: return getDayOfWeek();
|
||||
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((getDayOfWeek() - 1) % 7) + 1;
|
||||
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((dayOfMonth - 1) % 7) + 1;
|
||||
case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((getDayOfYear() - 1) % 7) + 1;
|
||||
case DAY_OF_MONTH: return this.dayOfMonth;
|
||||
case DAY_OF_YEAR: return this.getDayOfYear();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2016, 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
|
||||
@ -349,25 +349,40 @@ class DateTimeTextProvider {
|
||||
|
||||
if (field == MONTH_OF_YEAR) {
|
||||
for (TextStyle textStyle : TextStyle.values()) {
|
||||
Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames(
|
||||
"gregory", Calendar.MONTH, textStyle.toCalendarStyle(), locale);
|
||||
Map<Long, String> map = new HashMap<>();
|
||||
if (displayNames != null) {
|
||||
for (Entry<String, Integer> entry : displayNames.entrySet()) {
|
||||
map.put((long) (entry.getValue() + 1), entry.getKey());
|
||||
}
|
||||
|
||||
} else {
|
||||
// Narrow names may have duplicated names, such as "J" for January, Jun, July.
|
||||
// Get names one by one in that case.
|
||||
// Narrow names may have duplicated names, such as "J" for January, June, July.
|
||||
// Get names one by one in that case.
|
||||
if ((textStyle.equals(TextStyle.NARROW) ||
|
||||
textStyle.equals(TextStyle.NARROW_STANDALONE))) {
|
||||
for (int month = Calendar.JANUARY; month <= Calendar.DECEMBER; month++) {
|
||||
String name;
|
||||
name = CalendarDataUtility.retrieveJavaTimeFieldValueName(
|
||||
"gregory", Calendar.MONTH, month, textStyle.toCalendarStyle(), locale);
|
||||
"gregory", Calendar.MONTH,
|
||||
month, textStyle.toCalendarStyle(), locale);
|
||||
if (name == null) {
|
||||
break;
|
||||
}
|
||||
map.put((long) (month + 1), name);
|
||||
map.put((month + 1L), name);
|
||||
}
|
||||
} else {
|
||||
Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames(
|
||||
"gregory", Calendar.MONTH, textStyle.toCalendarStyle(), locale);
|
||||
if (displayNames != null) {
|
||||
for (Entry<String, Integer> entry : displayNames.entrySet()) {
|
||||
map.put((long)(entry.getValue() + 1), entry.getKey());
|
||||
}
|
||||
} else {
|
||||
// Although probability is very less, but if other styles have duplicate names.
|
||||
// Get names one by one in that case.
|
||||
for (int month = Calendar.JANUARY; month <= Calendar.DECEMBER; month++) {
|
||||
String name;
|
||||
name = CalendarDataUtility.retrieveJavaTimeFieldValueName(
|
||||
"gregory", Calendar.MONTH, month, textStyle.toCalendarStyle(), locale);
|
||||
if (name == null) {
|
||||
break;
|
||||
}
|
||||
map.put((month + 1L), name);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!map.isEmpty()) {
|
||||
@ -379,26 +394,41 @@ class DateTimeTextProvider {
|
||||
|
||||
if (field == DAY_OF_WEEK) {
|
||||
for (TextStyle textStyle : TextStyle.values()) {
|
||||
Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames(
|
||||
"gregory", Calendar.DAY_OF_WEEK, textStyle.toCalendarStyle(), locale);
|
||||
Map<Long, String> map = new HashMap<>();
|
||||
if (displayNames != null) {
|
||||
for (Entry<String, Integer> entry : displayNames.entrySet()) {
|
||||
map.put((long)toWeekDay(entry.getValue()), entry.getKey());
|
||||
}
|
||||
|
||||
} else {
|
||||
// Narrow names may have duplicated names, such as "S" for Sunday and Saturday.
|
||||
// Get names one by one in that case.
|
||||
// Narrow names may have duplicated names, such as "S" for Sunday and Saturday.
|
||||
// Get names one by one in that case.
|
||||
if ((textStyle.equals(TextStyle.NARROW) ||
|
||||
textStyle.equals(TextStyle.NARROW_STANDALONE))) {
|
||||
for (int wday = Calendar.SUNDAY; wday <= Calendar.SATURDAY; wday++) {
|
||||
String name;
|
||||
name = CalendarDataUtility.retrieveJavaTimeFieldValueName(
|
||||
"gregory", Calendar.DAY_OF_WEEK, wday, textStyle.toCalendarStyle(), locale);
|
||||
"gregory", Calendar.DAY_OF_WEEK,
|
||||
wday, textStyle.toCalendarStyle(), locale);
|
||||
if (name == null) {
|
||||
break;
|
||||
}
|
||||
map.put((long)toWeekDay(wday), name);
|
||||
}
|
||||
} else {
|
||||
Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames(
|
||||
"gregory", Calendar.DAY_OF_WEEK, textStyle.toCalendarStyle(), locale);
|
||||
if (displayNames != null) {
|
||||
for (Entry<String, Integer> entry : displayNames.entrySet()) {
|
||||
map.put((long)toWeekDay(entry.getValue()), entry.getKey());
|
||||
}
|
||||
} else {
|
||||
// Although probability is very less, but if other styles have duplicate names.
|
||||
// Get names one by one in that case.
|
||||
for (int wday = Calendar.SUNDAY; wday <= Calendar.SATURDAY; wday++) {
|
||||
String name;
|
||||
name = CalendarDataUtility.retrieveJavaTimeFieldValueName(
|
||||
"gregory", Calendar.DAY_OF_WEEK, wday, textStyle.toCalendarStyle(), locale);
|
||||
if (name == null) {
|
||||
break;
|
||||
}
|
||||
map.put((long)toWeekDay(wday), name);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!map.isEmpty()) {
|
||||
styleMap.put(textStyle, map);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2016, 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
|
||||
@ -236,7 +236,7 @@ public final class Optional<T> {
|
||||
* present, otherwise an empty {@code Optional}
|
||||
* @throws NullPointerException if the mapping function is {@code null}
|
||||
*/
|
||||
public<U> Optional<U> map(Function<? super T, ? extends U> mapper) {
|
||||
public <U> Optional<U> map(Function<? super T, ? extends U> mapper) {
|
||||
Objects.requireNonNull(mapper);
|
||||
if (!isPresent()) {
|
||||
return empty();
|
||||
@ -264,12 +264,14 @@ public final class Optional<T> {
|
||||
* @throws NullPointerException if the mapping function is {@code null} or
|
||||
* returns a {@code null} result
|
||||
*/
|
||||
public<U> Optional<U> flatMap(Function<? super T, Optional<U>> mapper) {
|
||||
public <U> Optional<U> flatMap(Function<? super T, ? extends Optional<? extends U>> mapper) {
|
||||
Objects.requireNonNull(mapper);
|
||||
if (!isPresent()) {
|
||||
return empty();
|
||||
} else {
|
||||
return Objects.requireNonNull(mapper.apply(value));
|
||||
@SuppressWarnings("unchecked")
|
||||
Optional<U> r = (Optional<U>) mapper.apply(value);
|
||||
return Objects.requireNonNull(r);
|
||||
}
|
||||
}
|
||||
|
||||
@ -286,12 +288,14 @@ public final class Optional<T> {
|
||||
* produces a {@code null} result
|
||||
* @since 9
|
||||
*/
|
||||
public Optional<T> or(Supplier<Optional<T>> supplier) {
|
||||
public Optional<T> or(Supplier<? extends Optional<? extends T>> supplier) {
|
||||
Objects.requireNonNull(supplier);
|
||||
if (isPresent()) {
|
||||
return this;
|
||||
} else {
|
||||
return Objects.requireNonNull(supplier.get());
|
||||
@SuppressWarnings("unchecked")
|
||||
Optional<T> r = (Optional<T>) supplier.get();
|
||||
return Objects.requireNonNull(r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -63,7 +63,7 @@ import sun.util.ResourceBundleEnumeration;
|
||||
* files containing the resource data. <code>ResourceBundle.getBundle</code>
|
||||
* will automatically look for the appropriate properties file and create a
|
||||
* <code>PropertyResourceBundle</code> that refers to it. See
|
||||
* {@link ResourceBundle#getBundle(java.lang.String, java.util.Locale, java.lang.ClassLoader) ResourceBundle.getBundle}
|
||||
* {@link ResourceBundle#getBundle(String, Locale, ClassLoader) ResourceBundle.getBundle}
|
||||
* for a complete description of the search and instantiation strategy.
|
||||
*
|
||||
* <p>
|
||||
@ -105,19 +105,14 @@ import sun.util.ResourceBundleEnumeration;
|
||||
* </pre>
|
||||
* </blockquote>
|
||||
*
|
||||
* <p>
|
||||
* The implementation of a {@code PropertyResourceBundle} subclass must be
|
||||
* thread-safe if it's simultaneously used by multiple threads. The default
|
||||
* implementations of the non-abstract methods in this class are thread-safe.
|
||||
*
|
||||
* <p>
|
||||
* <strong>Note:</strong> PropertyResourceBundle can be constructed either
|
||||
* from an InputStream or a Reader, which represents a property file.
|
||||
* Constructing a PropertyResourceBundle instance from an InputStream requires
|
||||
* that the input stream be encoded in UTF-8. By default, if a
|
||||
* @apiNote
|
||||
* {@code PropertyResourceBundle} can be constructed either
|
||||
* from an {@code InputStream} or a {@code Reader}, which represents a property file.
|
||||
* Constructing a {@code PropertyResourceBundle} instance from an {@code InputStream}
|
||||
* requires that the input stream be encoded in {@code UTF-8}. By default, if a
|
||||
* {@link java.nio.charset.MalformedInputException} or an
|
||||
* {@link java.nio.charset.UnmappableCharacterException} occurs on reading the
|
||||
* input stream, then the PropertyResourceBundle instance resets to the state
|
||||
* input stream, then the {@code PropertyResourceBundle} instance resets to the state
|
||||
* before the exception, re-reads the input stream in {@code ISO-8859-1}, and
|
||||
* continues reading. If the system property
|
||||
* {@code java.util.PropertyResourceBundle.encoding} is set to either
|
||||
@ -126,8 +121,15 @@ import sun.util.ResourceBundleEnumeration;
|
||||
* If "ISO-8859-1" is specified, characters that cannot be represented in
|
||||
* ISO-8859-1 encoding must be represented by Unicode Escapes as defined in section
|
||||
* 3.3 of <cite>The Java™ Language Specification</cite>
|
||||
* whereas the other constructor which takes a Reader does not have that limitation.
|
||||
* whereas the other constructor which takes a {@code Reader} does not have that limitation.
|
||||
* Other encoding values are ignored for this system property.
|
||||
* The system property is read and evaluated when initializing this class.
|
||||
* Changing or removing the property has no effect after the initialization.
|
||||
*
|
||||
* @implSpec
|
||||
* The implementation of a {@code PropertyResourceBundle} subclass must be
|
||||
* thread-safe if it's simultaneously used by multiple threads. The default
|
||||
* implementations of the non-abstract methods in this class are thread-safe.
|
||||
*
|
||||
* @see ResourceBundle
|
||||
* @see ListResourceBundle
|
||||
@ -144,16 +146,18 @@ public class PropertyResourceBundle extends ResourceBundle {
|
||||
|
||||
/**
|
||||
* Creates a property resource bundle from an {@link java.io.InputStream
|
||||
* InputStream}. This constructor reads the property file in UTF-8 by default.
|
||||
* If a {@link java.nio.charset.MalformedInputException} or an
|
||||
* {@link java.nio.charset.UnmappableCharacterException} occurs on reading the
|
||||
* input stream, then the PropertyResourceBundle instance resets to the state
|
||||
* before the exception, re-reads the input stream in {@code ISO-8859-1} and
|
||||
* continues reading. If the system property
|
||||
* {@code java.util.PropertyResourceBundle.encoding} is set to either
|
||||
* "ISO-8859-1" or "UTF-8", the input stream is solely read in that encoding,
|
||||
* and throws the exception if it encounters an invalid sequence. Other
|
||||
* encoding values are ignored for this system property.
|
||||
* InputStream}. This constructor reads the property file in UTF-8 by default.
|
||||
* If a {@link java.nio.charset.MalformedInputException} or an
|
||||
* {@link java.nio.charset.UnmappableCharacterException} occurs on reading the
|
||||
* input stream, then the PropertyResourceBundle instance resets to the state
|
||||
* before the exception, re-reads the input stream in {@code ISO-8859-1} and
|
||||
* continues reading. If the system property
|
||||
* {@code java.util.PropertyResourceBundle.encoding} is set to either
|
||||
* "ISO-8859-1" or "UTF-8", the input stream is solely read in that encoding,
|
||||
* and throws the exception if it encounters an invalid sequence. Other
|
||||
* encoding values are ignored for this system property.
|
||||
* The system property is read and evaluated when initializing this class.
|
||||
* Changing or removing the property has no effect after the initialization.
|
||||
*
|
||||
* @param stream an InputStream that represents a property file
|
||||
* to read from.
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
package jdk.internal.misc;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
public interface JavaNetInetAddressAccess {
|
||||
/**
|
||||
@ -33,4 +34,13 @@ public interface JavaNetInetAddressAccess {
|
||||
* the given InetAddress object.
|
||||
*/
|
||||
String getOriginalHostName(InetAddress ia);
|
||||
|
||||
/**
|
||||
* Get the InetAddress of the provided host. If an InetAddress is provided
|
||||
* then it will be the default address returned for all calls to either
|
||||
* form of getByName. This is required to maintain consistency when
|
||||
* caching addresses and hostnames.
|
||||
*/
|
||||
InetAddress getByName(String hostName, InetAddress hostAddress)
|
||||
throws UnknownHostException;
|
||||
}
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.internal.misc;
|
||||
|
||||
import java.net.URLClassLoader;
|
||||
import java.security.AccessControlContext;
|
||||
|
||||
public interface JavaNetURLClassLoaderAccess {
|
||||
AccessControlContext getAccessControlContext(URLClassLoader u);;
|
||||
}
|
||||
@ -27,6 +27,7 @@ package jdk.internal.misc;
|
||||
|
||||
import java.security.AccessControlContext;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
public interface JavaSecurityAccess {
|
||||
|
||||
@ -37,4 +38,5 @@ public interface JavaSecurityAccess {
|
||||
<T> T doIntersectionPrivilege(PrivilegedAction<T> action,
|
||||
AccessControlContext context);
|
||||
|
||||
ProtectionDomain[] getProtectDomains(AccessControlContext context);
|
||||
}
|
||||
|
||||
@ -57,6 +57,7 @@ public class SharedSecrets {
|
||||
private static JavaNetHttpCookieAccess javaNetHttpCookieAccess;
|
||||
private static JavaNetSocketAccess javaNetSocketAccess;
|
||||
private static JavaNetUriAccess javaNetUriAccess;
|
||||
private static JavaNetURLClassLoaderAccess javaNetURLClassLoaderAccess;
|
||||
private static JavaNioAccess javaNioAccess;
|
||||
private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
|
||||
private static JavaIOFilePermissionAccess javaIOFilePermissionAccess;
|
||||
@ -144,6 +145,16 @@ public class SharedSecrets {
|
||||
return javaNetUriAccess;
|
||||
}
|
||||
|
||||
public static void setJavaNetURLClassLoaderAccess(JavaNetURLClassLoaderAccess jnua) {
|
||||
javaNetURLClassLoaderAccess = jnua;
|
||||
}
|
||||
|
||||
public static JavaNetURLClassLoaderAccess getJavaNetURLClassLoaderAccess() {
|
||||
if (javaNetURLClassLoaderAccess == null)
|
||||
unsafe.ensureClassInitialized(java.net.URLClassLoader.class);
|
||||
return javaNetURLClassLoaderAccess;
|
||||
}
|
||||
|
||||
public static void setJavaNetInetAddressAccess(JavaNetInetAddressAccess jna) {
|
||||
javaNetInetAddressAccess = jna;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2016, 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
|
||||
@ -25,14 +25,25 @@
|
||||
|
||||
package jdk.internal.reflect;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamClass;
|
||||
import java.io.OptionalDataException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Executable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.security.Permission;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
|
||||
import sun.reflect.misc.ReflectUtil;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
@ -57,6 +68,9 @@ public class ReflectionFactory {
|
||||
// Provides access to package-private mechanisms in java.lang.reflect
|
||||
private static volatile LangReflectAccess langReflectAccess;
|
||||
|
||||
/* Method for static class initializer <clinit>, or null */
|
||||
private static volatile Method hasStaticInitializerMethod;
|
||||
|
||||
//
|
||||
// "Inflation" mechanism. Loading bytecodes to implement
|
||||
// Method.invoke() and Constructor.newInstance() currently costs
|
||||
@ -337,16 +351,41 @@ public class ReflectionFactory {
|
||||
//
|
||||
//
|
||||
|
||||
public Constructor<?> newConstructorForSerialization
|
||||
(Class<?> classToInstantiate, Constructor<?> constructorToCall)
|
||||
{
|
||||
// Fast path
|
||||
if (constructorToCall.getDeclaringClass() == classToInstantiate) {
|
||||
return constructorToCall;
|
||||
public final Constructor<?> newConstructorForExternalization(Class<?> cl) {
|
||||
if (!Externalizable.class.isAssignableFrom(cl)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Constructor<?> cons = cl.getConstructor();
|
||||
cons.setAccessible(true);
|
||||
return cons;
|
||||
} catch (NoSuchMethodException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final Constructor<?> newConstructorForSerialization(Class<?> cl) {
|
||||
Class<?> initCl = cl;
|
||||
while (Serializable.class.isAssignableFrom(initCl)) {
|
||||
if ((initCl = initCl.getSuperclass()) == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Constructor<?> constructorToCall;
|
||||
try {
|
||||
constructorToCall = initCl.getDeclaredConstructor();
|
||||
int mods = constructorToCall.getModifiers();
|
||||
if ((mods & Modifier.PRIVATE) != 0 ||
|
||||
((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
|
||||
!packageEquals(cl, initCl))) {
|
||||
return null;
|
||||
}
|
||||
} catch (NoSuchMethodException ex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ConstructorAccessor acc = new MethodAccessorGenerator().
|
||||
generateSerializationConstructor(classToInstantiate,
|
||||
generateSerializationConstructor(cl,
|
||||
constructorToCall.getParameterTypes(),
|
||||
constructorToCall.getExceptionTypes(),
|
||||
constructorToCall.getModifiers(),
|
||||
@ -364,9 +403,151 @@ public class ReflectionFactory {
|
||||
langReflectAccess().
|
||||
getConstructorParameterAnnotations(constructorToCall));
|
||||
setConstructorAccessor(c, acc);
|
||||
c.setAccessible(true);
|
||||
return c;
|
||||
}
|
||||
|
||||
public final MethodHandle readObjectForSerialization(Class<?> cl) {
|
||||
return findReadWriteObjectForSerialization(cl, "readObject", ObjectInputStream.class);
|
||||
}
|
||||
|
||||
public final MethodHandle readObjectNoDataForSerialization(Class<?> cl) {
|
||||
return findReadWriteObjectForSerialization(cl, "readObjectNoData", ObjectInputStream.class);
|
||||
}
|
||||
|
||||
public final MethodHandle writeObjectForSerialization(Class<?> cl) {
|
||||
return findReadWriteObjectForSerialization(cl, "writeObject", ObjectOutputStream.class);
|
||||
}
|
||||
|
||||
private final MethodHandle findReadWriteObjectForSerialization(Class<?> cl,
|
||||
String methodName,
|
||||
Class<?> streamClass) {
|
||||
if (!Serializable.class.isAssignableFrom(cl)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
Method meth = cl.getDeclaredMethod(methodName, streamClass);
|
||||
int mods = meth.getModifiers();
|
||||
if (meth.getReturnType() != Void.TYPE ||
|
||||
Modifier.isStatic(mods) ||
|
||||
!Modifier.isPrivate(mods)) {
|
||||
return null;
|
||||
}
|
||||
meth.setAccessible(true);
|
||||
return MethodHandles.lookup().unreflect(meth);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
return null;
|
||||
} catch (IllegalAccessException ex1) {
|
||||
throw new InternalError("Error", ex1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a MethodHandle for {@code writeReplace} on the serializable class
|
||||
* or null if no match found.
|
||||
* @param cl a serializable class
|
||||
* @returnss the {@code writeReplace} MethodHandle or {@code null} if not found
|
||||
*/
|
||||
public final MethodHandle writeReplaceForSerialization(Class<?> cl) {
|
||||
return getReplaceResolveForSerialization(cl, "writeReplace");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a MethodHandle for {@code readResolve} on the serializable class
|
||||
* or null if no match found.
|
||||
* @param cl a serializable class
|
||||
* @returns the {@code writeReplace} MethodHandle or {@code null} if not found
|
||||
*/
|
||||
public final MethodHandle readResolveForSerialization(Class<?> cl) {
|
||||
return getReplaceResolveForSerialization(cl, "readResolve");
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup readResolve or writeReplace on a class with specified
|
||||
* signature constraints.
|
||||
* @param cl a serializable class
|
||||
* @param methodName the method name to find
|
||||
* @returns a MethodHandle for the method or {@code null} if not found or
|
||||
* has the wrong signature.
|
||||
*/
|
||||
private MethodHandle getReplaceResolveForSerialization(Class<?> cl,
|
||||
String methodName) {
|
||||
if (!Serializable.class.isAssignableFrom(cl)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Class<?> defCl = cl;
|
||||
while (defCl != null) {
|
||||
try {
|
||||
Method m = defCl.getDeclaredMethod(methodName);
|
||||
if (m.getReturnType() != Object.class) {
|
||||
return null;
|
||||
}
|
||||
int mods = m.getModifiers();
|
||||
if (Modifier.isStatic(mods) | Modifier.isAbstract(mods)) {
|
||||
return null;
|
||||
} else if (Modifier.isPublic(mods) | Modifier.isProtected(mods)) {
|
||||
// fall through
|
||||
} else if (Modifier.isPrivate(mods) && (cl != defCl)) {
|
||||
return null;
|
||||
} else if (!packageEquals(cl, defCl)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
// Normal return
|
||||
m.setAccessible(true);
|
||||
return MethodHandles.lookup().unreflect(m);
|
||||
} catch (IllegalAccessException ex0) {
|
||||
// setAccessible should prevent IAE
|
||||
throw new InternalError("Error", ex0);
|
||||
}
|
||||
} catch (NoSuchMethodException ex) {
|
||||
defCl = defCl.getSuperclass();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given class defines a static initializer method,
|
||||
* false otherwise.
|
||||
*/
|
||||
public final boolean hasStaticInitializerForSerialization(Class<?> cl) {
|
||||
Method m = hasStaticInitializerMethod;
|
||||
if (m == null) {
|
||||
try {
|
||||
m = ObjectStreamClass.class.getDeclaredMethod("hasStaticInitializer",
|
||||
new Class<?>[]{Class.class});
|
||||
m.setAccessible(true);
|
||||
hasStaticInitializerMethod = m;
|
||||
} catch (NoSuchMethodException ex) {
|
||||
throw new InternalError("No such method hasStaticInitializer on "
|
||||
+ ObjectStreamClass.class, ex);
|
||||
}
|
||||
}
|
||||
try {
|
||||
return (Boolean) m.invoke(null, cl);
|
||||
} catch (InvocationTargetException | IllegalAccessException ex) {
|
||||
throw new InternalError("Exception invoking hasStaticInitializer", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the accessible constructor for OptionalDataException signaling eof.
|
||||
* @returns the eof constructor for OptionalDataException
|
||||
*/
|
||||
public final Constructor<OptionalDataException> newOptionalDataExceptionForSerialization() {
|
||||
try {
|
||||
Constructor<OptionalDataException> boolCtor =
|
||||
OptionalDataException.class.getDeclaredConstructor(Boolean.TYPE);
|
||||
boolCtor.setAccessible(true);
|
||||
return boolCtor;
|
||||
} catch (NoSuchMethodException ex) {
|
||||
throw new InternalError("Constructor not found", ex);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Internals only below this point
|
||||
@ -426,4 +607,17 @@ public class ReflectionFactory {
|
||||
}
|
||||
return langReflectAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if classes are defined in the classloader and same package, false
|
||||
* otherwise.
|
||||
* @param cl1 a class
|
||||
* @param cl2 another class
|
||||
* @returns true if the two classes are in the same classloader and package
|
||||
*/
|
||||
private static boolean packageEquals(Class<?> cl1, Class<?> cl2) {
|
||||
return cl1.getClassLoader() == cl2.getClassLoader() &&
|
||||
Objects.equals(cl1.getPackage(), cl2.getPackage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -240,8 +240,7 @@ module java.base {
|
||||
java.xml.ws;
|
||||
exports sun.security.action to
|
||||
java.desktop,
|
||||
java.security.jgss,
|
||||
jdk.crypto.pkcs11;
|
||||
java.security.jgss;
|
||||
exports sun.security.internal.interfaces to
|
||||
jdk.crypto.pkcs11;
|
||||
exports sun.security.internal.spec to
|
||||
@ -267,6 +266,8 @@ module java.base {
|
||||
jdk.crypto.pkcs11;
|
||||
exports sun.security.ssl to
|
||||
java.security.jgss;
|
||||
exports sun.security.timestamp to
|
||||
jdk.jartool;
|
||||
exports sun.security.tools to
|
||||
jdk.jartool;
|
||||
exports sun.security.util to
|
||||
|
||||
@ -498,6 +498,23 @@ public class SignerInfo implements DerEncoder {
|
||||
return unauthenticatedAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timestamp PKCS7 data unverified.
|
||||
* @return a PKCS7 object
|
||||
*/
|
||||
public PKCS7 getTsToken() throws IOException {
|
||||
if (unauthenticatedAttributes == null) {
|
||||
return null;
|
||||
}
|
||||
PKCS9Attribute tsTokenAttr =
|
||||
unauthenticatedAttributes.getAttribute(
|
||||
PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_OID);
|
||||
if (tsTokenAttr == null) {
|
||||
return null;
|
||||
}
|
||||
return new PKCS7((byte[])tsTokenAttr.getValue());
|
||||
}
|
||||
|
||||
/*
|
||||
* Extracts a timestamp from a PKCS7 SignerInfo.
|
||||
*
|
||||
@ -525,19 +542,12 @@ public class SignerInfo implements DerEncoder {
|
||||
if (timestamp != null || !hasTimestamp)
|
||||
return timestamp;
|
||||
|
||||
if (unauthenticatedAttributes == null) {
|
||||
hasTimestamp = false;
|
||||
return null;
|
||||
}
|
||||
PKCS9Attribute tsTokenAttr =
|
||||
unauthenticatedAttributes.getAttribute(
|
||||
PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_OID);
|
||||
if (tsTokenAttr == null) {
|
||||
PKCS7 tsToken = getTsToken();
|
||||
if (tsToken == null) {
|
||||
hasTimestamp = false;
|
||||
return null;
|
||||
}
|
||||
|
||||
PKCS7 tsToken = new PKCS7((byte[])tsTokenAttr.getValue());
|
||||
// Extract the content (an encoded timestamp token info)
|
||||
byte[] encTsTokenInfo = tsToken.getContentInfo().getData();
|
||||
// Extract the signer (the Timestamping Authority)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, 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
|
||||
@ -37,15 +37,10 @@
|
||||
* This notice and attribution to Taligent may not be removed.
|
||||
* Taligent is a registered trademark of Taligent, Inc.
|
||||
*/
|
||||
package sun.util.locale.provider;
|
||||
package sun.text;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Module;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.nio.BufferUnderflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.MissingResourceException;
|
||||
import sun.text.CompactByteArray;
|
||||
import sun.text.SupplementaryCharacterData;
|
||||
@ -137,131 +132,90 @@ class BreakDictionary {
|
||||
// deserialization
|
||||
//=========================================================================
|
||||
|
||||
BreakDictionary(Module module, String dictionaryName)
|
||||
throws IOException, MissingResourceException {
|
||||
|
||||
readDictionaryFile(module, dictionaryName);
|
||||
BreakDictionary(String dictionaryName, byte[] dictionaryData) {
|
||||
try {
|
||||
setupDictionary(dictionaryName, dictionaryData);
|
||||
} catch (BufferUnderflowException bue) {
|
||||
MissingResourceException e;
|
||||
e = new MissingResourceException("Corrupted dictionary data",
|
||||
dictionaryName, "");
|
||||
e.initCause(bue);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private void readDictionaryFile(final Module module, final String dictionaryName)
|
||||
throws IOException, MissingResourceException {
|
||||
|
||||
BufferedInputStream in;
|
||||
try {
|
||||
PrivilegedExceptionAction<BufferedInputStream> pa = () -> {
|
||||
String pathName = "jdk.localedata".equals(module.getName()) ?
|
||||
"sun/text/resources/ext/" :
|
||||
"sun/text/resources/";
|
||||
InputStream is = module.getResourceAsStream(pathName + dictionaryName);
|
||||
if (is == null) {
|
||||
// Try to load the file with "java.base" module instance. Assumption
|
||||
// here is that the fall back data files to be read should reside in
|
||||
// java.base.
|
||||
is = BreakDictionary.class.getModule().getResourceAsStream("sun/text/resources/" + dictionaryName);
|
||||
}
|
||||
|
||||
return new BufferedInputStream(is);
|
||||
};
|
||||
in = AccessController.doPrivileged(pa);
|
||||
}
|
||||
catch (PrivilegedActionException e) {
|
||||
throw new InternalError(e.toString(), e);
|
||||
}
|
||||
|
||||
byte[] buf = new byte[8];
|
||||
if (in.read(buf) != 8) {
|
||||
throw new MissingResourceException("Wrong data length",
|
||||
dictionaryName, "");
|
||||
}
|
||||
private void setupDictionary(String dictionaryName, byte[] dictionaryData) {
|
||||
ByteBuffer bb = ByteBuffer.wrap(dictionaryData);
|
||||
|
||||
// check version
|
||||
int version = RuleBasedBreakIterator.getInt(buf, 0);
|
||||
int version = bb.getInt();
|
||||
if (version != supportedVersion) {
|
||||
throw new MissingResourceException("Dictionary version(" + version + ") is unsupported",
|
||||
dictionaryName, "");
|
||||
}
|
||||
|
||||
// get data size
|
||||
int len = RuleBasedBreakIterator.getInt(buf, 4);
|
||||
buf = new byte[len];
|
||||
if (in.read(buf) != len) {
|
||||
throw new MissingResourceException("Wrong data length",
|
||||
dictionaryName, "");
|
||||
}
|
||||
|
||||
// close the stream
|
||||
in.close();
|
||||
|
||||
int l;
|
||||
int offset = 0;
|
||||
// Check data size
|
||||
int len = bb.getInt();
|
||||
if (bb.position() + len != bb.limit()) {
|
||||
throw new MissingResourceException("Dictionary size is wrong: " + bb.limit(),
|
||||
dictionaryName, "");
|
||||
}
|
||||
|
||||
// read in the column map for BMP characteres (this is serialized in
|
||||
// its internal form: an index array followed by a data array)
|
||||
l = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
short[] temp = new short[l];
|
||||
for (int i = 0; i < l; i++, offset+=2) {
|
||||
temp[i] = RuleBasedBreakIterator.getShort(buf, offset);
|
||||
}
|
||||
l = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
byte[] temp2 = new byte[l];
|
||||
for (int i = 0; i < l; i++, offset++) {
|
||||
temp2[i] = buf[offset];
|
||||
len = bb.getInt();
|
||||
short[] temp = new short[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
temp[i] = bb.getShort();
|
||||
}
|
||||
len = bb.getInt();
|
||||
byte[] temp2 = new byte[len];
|
||||
bb.get(temp2);
|
||||
columnMap = new CompactByteArray(temp, temp2);
|
||||
|
||||
// read in numCols and numColGroups
|
||||
numCols = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
numColGroups = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
numCols = bb.getInt();
|
||||
numColGroups = bb.getInt();
|
||||
|
||||
// read in the row-number index
|
||||
l = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
rowIndex = new short[l];
|
||||
for (int i = 0; i < l; i++, offset+=2) {
|
||||
rowIndex[i] = RuleBasedBreakIterator.getShort(buf, offset);
|
||||
len = bb.getInt();
|
||||
rowIndex = new short[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
rowIndex[i] = bb.getShort();
|
||||
}
|
||||
|
||||
// load in the populated-cells bitmap: index first, then bitmap list
|
||||
l = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
rowIndexFlagsIndex = new short[l];
|
||||
for (int i = 0; i < l; i++, offset+=2) {
|
||||
rowIndexFlagsIndex[i] = RuleBasedBreakIterator.getShort(buf, offset);
|
||||
len = bb.getInt();
|
||||
rowIndexFlagsIndex = new short[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
rowIndexFlagsIndex[i] = bb.getShort();
|
||||
}
|
||||
l = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
rowIndexFlags = new int[l];
|
||||
for (int i = 0; i < l; i++, offset+=4) {
|
||||
rowIndexFlags[i] = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
len = bb.getInt();
|
||||
rowIndexFlags = new int[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
rowIndexFlags[i] = bb.getInt();
|
||||
}
|
||||
|
||||
// load in the row-shift index
|
||||
l = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
rowIndexShifts = new byte[l];
|
||||
for (int i = 0; i < l; i++, offset++) {
|
||||
rowIndexShifts[i] = buf[offset];
|
||||
}
|
||||
len = bb.getInt();
|
||||
rowIndexShifts = new byte[len];
|
||||
bb.get(rowIndexShifts);
|
||||
|
||||
// load in the actual state table
|
||||
l = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
table = new short[l];
|
||||
for (int i = 0; i < l; i++, offset+=2) {
|
||||
table[i] = RuleBasedBreakIterator.getShort(buf, offset);
|
||||
len = bb.getInt();
|
||||
table = new short[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
table[i] = bb.getShort();
|
||||
}
|
||||
|
||||
// finally, prepare the column map for supplementary characters
|
||||
l = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
offset += 4;
|
||||
int[] temp3 = new int[l];
|
||||
for (int i = 0; i < l; i++, offset+=4) {
|
||||
temp3[i] = RuleBasedBreakIterator.getInt(buf, offset);
|
||||
len = bb.getInt();
|
||||
int[] temp3 = new int[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
temp3[i] = bb.getInt();
|
||||
}
|
||||
assert bb.position() == bb.limit();
|
||||
|
||||
supplementaryCharColumnMap = new SupplementaryCharacterData(temp3);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, 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
|
||||
@ -38,10 +38,8 @@
|
||||
* Taligent is a registered trademark of Taligent, Inc.
|
||||
*/
|
||||
|
||||
package sun.util.locale.provider;
|
||||
package sun.text;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Module;
|
||||
import java.text.CharacterIterator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -72,7 +70,7 @@ import java.util.Stack;
|
||||
* slow) BuildDictionaryFile utility for creating dictionary files, but aren't
|
||||
* currently making it public. Contact us for help.
|
||||
*/
|
||||
class DictionaryBasedBreakIterator extends RuleBasedBreakIterator {
|
||||
public class DictionaryBasedBreakIterator extends RuleBasedBreakIterator {
|
||||
|
||||
/**
|
||||
* a list of known words that is used to divide up contiguous ranges of letters,
|
||||
@ -109,18 +107,22 @@ class DictionaryBasedBreakIterator extends RuleBasedBreakIterator {
|
||||
|
||||
/**
|
||||
* Constructs a DictionaryBasedBreakIterator.
|
||||
* @param module The module where the dictionary file resides
|
||||
* @param dictionaryFilename The filename of the dictionary file to use
|
||||
*
|
||||
* @param ruleFile the name of the rule data file
|
||||
* @param ruleData the rule data loaded from the rule data file
|
||||
* @param dictionaryFile the name of the dictionary file
|
||||
* @param dictionartData the dictionary data loaded from the dictionary file
|
||||
* @throws MissingResourceException if rule data or dictionary initialization failed
|
||||
*/
|
||||
DictionaryBasedBreakIterator(Module module, String dataFile, String dictionaryFile)
|
||||
throws IOException {
|
||||
super(module, dataFile);
|
||||
public DictionaryBasedBreakIterator(String ruleFile, byte[] ruleData,
|
||||
String dictionaryFile, byte[] dictionaryData) {
|
||||
super(ruleFile, ruleData);
|
||||
byte[] tmp = super.getAdditionalData();
|
||||
if (tmp != null) {
|
||||
prepareCategoryFlags(tmp);
|
||||
super.setAdditionalData(null);
|
||||
}
|
||||
dictionary = new BreakDictionary(module, dictionaryFile);
|
||||
dictionary = new BreakDictionary(dictionaryFile, dictionaryData);
|
||||
}
|
||||
|
||||
private void prepareCategoryFlags(byte[] data) {
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, 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
|
||||
@ -38,15 +38,10 @@
|
||||
* Taligent is a registered trademark of Taligent, Inc.
|
||||
*/
|
||||
|
||||
package sun.util.locale.provider;
|
||||
package sun.text;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Module;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.nio.BufferUnderflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.text.BreakIterator;
|
||||
import java.text.CharacterIterator;
|
||||
import java.text.StringCharacterIterator;
|
||||
@ -218,7 +213,7 @@ import sun.text.SupplementaryCharacterData;
|
||||
*
|
||||
* @author Richard Gillam
|
||||
*/
|
||||
class RuleBasedBreakIterator extends BreakIterator {
|
||||
public class RuleBasedBreakIterator extends BreakIterator {
|
||||
|
||||
/**
|
||||
* A token used as a character-category value to identify ignore characters
|
||||
@ -249,11 +244,6 @@ class RuleBasedBreakIterator extends BreakIterator {
|
||||
*/
|
||||
static final byte supportedVersion = 1;
|
||||
|
||||
/**
|
||||
* Header size in byte count
|
||||
*/
|
||||
private static final int HEADER_LENGTH = 36;
|
||||
|
||||
/**
|
||||
* An array length of indices for BMP characters
|
||||
*/
|
||||
@ -315,16 +305,26 @@ class RuleBasedBreakIterator extends BreakIterator {
|
||||
//=======================================================================
|
||||
|
||||
/**
|
||||
* Constructs a RuleBasedBreakIterator according to the module and the datafile
|
||||
* provided.
|
||||
* Constructs a RuleBasedBreakIterator using the given rule data.
|
||||
*
|
||||
* @throws MissingResourceException if the rule data is invalid or corrupted
|
||||
*/
|
||||
RuleBasedBreakIterator(Module module, String datafile)
|
||||
throws IOException, MissingResourceException {
|
||||
readTables(module, datafile);
|
||||
public RuleBasedBreakIterator(String ruleFile, byte[] ruleData) {
|
||||
ByteBuffer bb = ByteBuffer.wrap(ruleData);
|
||||
try {
|
||||
validateRuleData(ruleFile, bb);
|
||||
setupTables(ruleFile, bb);
|
||||
} catch (BufferUnderflowException bue) {
|
||||
MissingResourceException e;
|
||||
e = new MissingResourceException("Corrupted rule data file", ruleFile, "");
|
||||
e.initCause(bue);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read datafile. The datafile's format is as follows:
|
||||
* Initializes the fields with the given rule data.
|
||||
* The data format is as follows:
|
||||
* <pre>
|
||||
* BreakIteratorData {
|
||||
* u1 magic[7];
|
||||
@ -370,133 +370,101 @@ class RuleBasedBreakIterator extends BreakIterator {
|
||||
* u1 additionalData[additionalDataLength];
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @throws BufferUnderflowException if the end-of-data is reached before
|
||||
* setting up all the tables
|
||||
*/
|
||||
protected final void readTables(Module module, String datafile)
|
||||
throws IOException, MissingResourceException {
|
||||
|
||||
byte[] buffer = readFile(module, datafile);
|
||||
|
||||
private void setupTables(String ruleFile, ByteBuffer bb) {
|
||||
/* Read header_info. */
|
||||
int stateTableLength = getInt(buffer, 0);
|
||||
int backwardsStateTableLength = getInt(buffer, 4);
|
||||
int endStatesLength = getInt(buffer, 8);
|
||||
int lookaheadStatesLength = getInt(buffer, 12);
|
||||
int BMPdataLength = getInt(buffer, 16);
|
||||
int nonBMPdataLength = getInt(buffer, 20);
|
||||
int additionalDataLength = getInt(buffer, 24);
|
||||
checksum = getLong(buffer, 28);
|
||||
int stateTableLength = bb.getInt();
|
||||
int backwardsStateTableLength = bb.getInt();
|
||||
int endStatesLength = bb.getInt();
|
||||
int lookaheadStatesLength = bb.getInt();
|
||||
int BMPdataLength = bb.getInt();
|
||||
int nonBMPdataLength = bb.getInt();
|
||||
int additionalDataLength = bb.getInt();
|
||||
checksum = bb.getLong();
|
||||
|
||||
/* Read stateTable[numCategories * numRows] */
|
||||
stateTable = new short[stateTableLength];
|
||||
int offset = HEADER_LENGTH;
|
||||
for (int i = 0; i < stateTableLength; i++, offset+=2) {
|
||||
stateTable[i] = getShort(buffer, offset);
|
||||
for (int i = 0; i < stateTableLength; i++) {
|
||||
stateTable[i] = bb.getShort();
|
||||
}
|
||||
|
||||
/* Read backwardsStateTable[numCategories * numRows] */
|
||||
backwardsStateTable = new short[backwardsStateTableLength];
|
||||
for (int i = 0; i < backwardsStateTableLength; i++, offset+=2) {
|
||||
backwardsStateTable[i] = getShort(buffer, offset);
|
||||
for (int i = 0; i < backwardsStateTableLength; i++) {
|
||||
backwardsStateTable[i] = bb.getShort();
|
||||
}
|
||||
|
||||
/* Read endStates[numRows] */
|
||||
endStates = new boolean[endStatesLength];
|
||||
for (int i = 0; i < endStatesLength; i++, offset++) {
|
||||
endStates[i] = buffer[offset] == 1;
|
||||
for (int i = 0; i < endStatesLength; i++) {
|
||||
endStates[i] = bb.get() == 1;
|
||||
}
|
||||
|
||||
/* Read lookaheadStates[numRows] */
|
||||
lookaheadStates = new boolean[lookaheadStatesLength];
|
||||
for (int i = 0; i < lookaheadStatesLength; i++, offset++) {
|
||||
lookaheadStates[i] = buffer[offset] == 1;
|
||||
for (int i = 0; i < lookaheadStatesLength; i++) {
|
||||
lookaheadStates[i] = bb.get() == 1;
|
||||
}
|
||||
|
||||
/* Read a category table and indices for BMP characters. */
|
||||
short[] temp1 = new short[BMP_INDICES_LENGTH]; // BMPindices
|
||||
for (int i = 0; i < BMP_INDICES_LENGTH; i++, offset+=2) {
|
||||
temp1[i] = getShort(buffer, offset);
|
||||
for (int i = 0; i < BMP_INDICES_LENGTH; i++) {
|
||||
temp1[i] = bb.getShort();
|
||||
}
|
||||
byte[] temp2 = new byte[BMPdataLength]; // BMPdata
|
||||
System.arraycopy(buffer, offset, temp2, 0, BMPdataLength);
|
||||
offset += BMPdataLength;
|
||||
bb.get(temp2);
|
||||
charCategoryTable = new CompactByteArray(temp1, temp2);
|
||||
|
||||
/* Read a category table for non-BMP characters. */
|
||||
int[] temp3 = new int[nonBMPdataLength];
|
||||
for (int i = 0; i < nonBMPdataLength; i++, offset+=4) {
|
||||
temp3[i] = getInt(buffer, offset);
|
||||
for (int i = 0; i < nonBMPdataLength; i++) {
|
||||
temp3[i] = bb.getInt();
|
||||
}
|
||||
supplementaryCharCategoryTable = new SupplementaryCharacterData(temp3);
|
||||
|
||||
/* Read additional data */
|
||||
if (additionalDataLength > 0) {
|
||||
additionalData = new byte[additionalDataLength];
|
||||
System.arraycopy(buffer, offset, additionalData, 0, additionalDataLength);
|
||||
bb.get(additionalData);
|
||||
}
|
||||
assert bb.position() == bb.limit();
|
||||
|
||||
/* Set numCategories */
|
||||
numCategories = stateTable.length / endStates.length;
|
||||
}
|
||||
|
||||
protected byte[] readFile(final Module module, final String datafile)
|
||||
throws IOException, MissingResourceException {
|
||||
|
||||
BufferedInputStream is;
|
||||
try {
|
||||
PrivilegedExceptionAction<BufferedInputStream> pa = () -> {
|
||||
String pathName = "jdk.localedata".equals(module.getName()) ?
|
||||
"sun/text/resources/ext/" :
|
||||
"sun/text/resources/";
|
||||
InputStream in = module.getResourceAsStream(pathName + datafile);
|
||||
if (in == null) {
|
||||
// Try to load the file with "java.base" module instance. Assumption
|
||||
// here is that the fall back data files to be read should reside in
|
||||
// java.base.
|
||||
in = RuleBasedBreakIterator.class.getModule().getResourceAsStream("sun/text/resources/" + datafile);
|
||||
}
|
||||
|
||||
return new BufferedInputStream(in);
|
||||
};
|
||||
is = AccessController.doPrivileged(pa);
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw new InternalError(e.toString(), e);
|
||||
}
|
||||
|
||||
int offset = 0;
|
||||
|
||||
/* First, read magic, version, and header_info. */
|
||||
int len = LABEL_LENGTH + 5;
|
||||
byte[] buf = new byte[len];
|
||||
if (is.read(buf) != len) {
|
||||
throw new MissingResourceException("Wrong header length",
|
||||
datafile, "");
|
||||
}
|
||||
|
||||
/* Validate the magic number. */
|
||||
for (int i = 0; i < LABEL_LENGTH; i++, offset++) {
|
||||
if (buf[offset] != LABEL[offset]) {
|
||||
/**
|
||||
* Validates the magic number, version, and the length of the given data.
|
||||
*
|
||||
* @throws BufferUnderflowException if the end-of-data is reached while
|
||||
* validating data
|
||||
* @throws MissingResourceException if valification failed
|
||||
*/
|
||||
void validateRuleData(String ruleFile, ByteBuffer bb) {
|
||||
/* Verify the magic number. */
|
||||
for (int i = 0; i < LABEL_LENGTH; i++) {
|
||||
if (bb.get() != LABEL[i]) {
|
||||
throw new MissingResourceException("Wrong magic number",
|
||||
datafile, "");
|
||||
ruleFile, "");
|
||||
}
|
||||
}
|
||||
|
||||
/* Validate the version number. */
|
||||
if (buf[offset] != supportedVersion) {
|
||||
throw new MissingResourceException("Unsupported version(" + buf[offset] + ")",
|
||||
datafile, "");
|
||||
/* Verify the version number. */
|
||||
byte version = bb.get();
|
||||
if (version != supportedVersion) {
|
||||
throw new MissingResourceException("Unsupported version(" + version + ")",
|
||||
ruleFile, "");
|
||||
}
|
||||
|
||||
/* Read data: totalDataSize + 8(for checksum) */
|
||||
len = getInt(buf, ++offset);
|
||||
buf = new byte[len];
|
||||
if (is.read(buf) != len) {
|
||||
// Check the length of the rest of data
|
||||
int len = bb.getInt();
|
||||
if (bb.position() + len != bb.limit()) {
|
||||
throw new MissingResourceException("Wrong data length",
|
||||
datafile, "");
|
||||
ruleFile, "");
|
||||
}
|
||||
|
||||
is.close();
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
byte[] getAdditionalData() {
|
||||
@ -1061,28 +1029,6 @@ class RuleBasedBreakIterator extends BreakIterator {
|
||||
return backwardsStateTable[state * numCategories + category];
|
||||
}
|
||||
|
||||
static long getLong(byte[] buf, int offset) {
|
||||
long num = buf[offset]&0xFF;
|
||||
for (int i = 1; i < 8; i++) {
|
||||
num = num<<8 | (buf[offset+i]&0xFF);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
static int getInt(byte[] buf, int offset) {
|
||||
int num = buf[offset]&0xFF;
|
||||
for (int i = 1; i < 4; i++) {
|
||||
num = num<<8 | (buf[offset+i]&0xFF);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
static short getShort(byte[] buf, int offset) {
|
||||
short num = (short)(buf[offset]&0xFF);
|
||||
num = (short)(num<<8 | (buf[offset+1]&0xFF));
|
||||
return num;
|
||||
}
|
||||
|
||||
/*
|
||||
* This class exists to work around a bug in incorrect implementations
|
||||
* of CharacterIterator, which incorrectly handle setIndex(endIndex).
|
||||
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.text.resources;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
import sun.util.resources.BreakIteratorResourceBundle;
|
||||
|
||||
public class BreakIteratorResources extends BreakIteratorResourceBundle {
|
||||
@Override
|
||||
protected ResourceBundle getBreakIteratorInfo() {
|
||||
return new BreakIteratorInfo();
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2016, 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
|
||||
@ -32,6 +32,8 @@ import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import sun.text.DictionaryBasedBreakIterator;
|
||||
import sun.text.RuleBasedBreakIterator;
|
||||
|
||||
/**
|
||||
* Concrete implementation of the {@link java.text.spi.BreakIteratorProvider
|
||||
@ -153,29 +155,31 @@ public class BreakIteratorProviderImpl extends BreakIteratorProvider
|
||||
}
|
||||
|
||||
private BreakIterator getBreakInstance(Locale locale,
|
||||
int type,
|
||||
String dataName,
|
||||
String dictionaryName) {
|
||||
int type,
|
||||
String ruleName,
|
||||
String dictionaryName) {
|
||||
Objects.requireNonNull(locale);
|
||||
|
||||
LocaleResources lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
|
||||
String[] classNames = (String[]) lr.getBreakIteratorInfo("BreakIteratorClasses");
|
||||
String dataFile = (String) lr.getBreakIteratorInfo(dataName);
|
||||
String ruleFile = (String) lr.getBreakIteratorInfo(ruleName);
|
||||
byte[] ruleData = lr.getBreakIteratorResources(ruleName);
|
||||
|
||||
try {
|
||||
switch (classNames[type]) {
|
||||
case "RuleBasedBreakIterator":
|
||||
return new RuleBasedBreakIterator(
|
||||
lr.getBreakIteratorDataModule(), dataFile);
|
||||
return new RuleBasedBreakIterator(ruleFile, ruleData);
|
||||
|
||||
case "DictionaryBasedBreakIterator":
|
||||
String dictionaryFile = (String) lr.getBreakIteratorInfo(dictionaryName);
|
||||
return new DictionaryBasedBreakIterator(
|
||||
lr.getBreakIteratorDataModule(), dataFile, dictionaryFile);
|
||||
byte[] dictionaryData = lr.getBreakIteratorResources(dictionaryName);
|
||||
return new DictionaryBasedBreakIterator(ruleFile, ruleData,
|
||||
dictionaryFile, dictionaryData);
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid break iterator class \"" +
|
||||
classNames[type] + "\"");
|
||||
}
|
||||
} catch (IOException | MissingResourceException | IllegalArgumentException e) {
|
||||
} catch (MissingResourceException | IllegalArgumentException e) {
|
||||
throw new InternalError(e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2016, 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
|
||||
@ -42,7 +42,6 @@ package sun.util.locale.provider;
|
||||
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.lang.reflect.Module;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.LinkedHashSet;
|
||||
@ -113,13 +112,14 @@ public class LocaleResources {
|
||||
if (data == null || ((biInfo = data.get()) == null)) {
|
||||
biInfo = localeData.getBreakIteratorInfo(locale).getObject(key);
|
||||
cache.put(cacheKey, new ResourceReference(cacheKey, biInfo, referenceQueue));
|
||||
}
|
||||
}
|
||||
|
||||
return biInfo;
|
||||
}
|
||||
|
||||
Module getBreakIteratorDataModule() {
|
||||
return localeData.getBreakIteratorInfo(locale).getClass().getModule();
|
||||
@SuppressWarnings("unchecked")
|
||||
byte[] getBreakIteratorResources(String key) {
|
||||
return (byte[]) localeData.getBreakIteratorResources(locale).getObject(key);
|
||||
}
|
||||
|
||||
int getCalendarData(String key) {
|
||||
|
||||
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.util.resources;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* BreakIteratorResourceBundle is an abstract class for loading BreakIterator
|
||||
* data (rules or dictionary) from each module. An implementation class must
|
||||
* implement getBreakIteratorInfo() that returns an instance of the
|
||||
* corresponding BreakIteratorInfo (basename). The data name is taken from the
|
||||
* BreakIteratorInfo instance.
|
||||
*
|
||||
* <p>For example, if the given key is "WordDictionary" and Locale is "th", the
|
||||
* data name is taken from a BreakIteratorInfo_th and the key's value is
|
||||
* "thai_dict". Its data thai_dict is loaded from the Module of the
|
||||
* implementation class of this class.
|
||||
*/
|
||||
|
||||
public abstract class BreakIteratorResourceBundle extends ResourceBundle {
|
||||
// If any keys that are not for data names are added to BreakIteratorInfo*,
|
||||
// those keys must be added to NON_DATA_KEYS.
|
||||
private static final Set<String> NON_DATA_KEYS = Set.of("BreakIteratorClasses");
|
||||
|
||||
private volatile Set<String> keys;
|
||||
|
||||
/**
|
||||
* Returns an instance of the corresponding {@code BreakIteratorInfo} (basename).
|
||||
* The instance shouldn't have its parent.
|
||||
*/
|
||||
protected abstract ResourceBundle getBreakIteratorInfo();
|
||||
|
||||
@Override
|
||||
protected Object handleGetObject(String key) {
|
||||
if (NON_DATA_KEYS.contains(key)) {
|
||||
return null;
|
||||
}
|
||||
ResourceBundle info = getBreakIteratorInfo();
|
||||
if (!info.containsKey(key)) {
|
||||
return null;
|
||||
}
|
||||
String path = getClass().getPackage().getName().replace('.', '/')
|
||||
+ '/' + info.getString(key);
|
||||
byte[] data;
|
||||
try (InputStream is = getResourceAsStream(path)) {
|
||||
data = is.readAllBytes();
|
||||
} catch (Exception e) {
|
||||
throw new InternalError("Can't load " + path, e);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private InputStream getResourceAsStream(String path) throws Exception {
|
||||
PrivilegedExceptionAction<InputStream> pa;
|
||||
pa = () -> getClass().getModule().getResourceAsStream(path);
|
||||
InputStream is;
|
||||
try {
|
||||
is = AccessController.doPrivileged(pa);
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw e.getException();
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getKeys() {
|
||||
return Collections.enumeration(keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<String> handleKeySet() {
|
||||
if (keys == null) {
|
||||
ResourceBundle info = getBreakIteratorInfo();
|
||||
Set<String> k = info.keySet();
|
||||
k.removeAll(NON_DATA_KEYS);
|
||||
synchronized (this) {
|
||||
if (keys == null) {
|
||||
keys = k;
|
||||
}
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
@ -122,6 +122,14 @@ public class LocaleData {
|
||||
return getBundle(type.getTextResourcesPackage() + ".BreakIteratorInfo", locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a break iterator resources resource bundle, using
|
||||
* privileges to allow accessing a sun.* package.
|
||||
*/
|
||||
public ResourceBundle getBreakIteratorResources(Locale locale) {
|
||||
return getBundle(type.getTextResourcesPackage() + ".BreakIteratorResources", locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a collation data resource bundle, using privileges
|
||||
* to allow accessing a sun.* package.
|
||||
|
||||
@ -655,6 +655,44 @@ krb5.kdc.bad.policy = tryLast
|
||||
jdk.certpath.disabledAlgorithms=MD2, MD5, SHA1 jdkCA & denyAfter 2017-01-01, \
|
||||
RSA keySize < 1024, DSA keySize < 1024, EC keySize < 224
|
||||
|
||||
# Algorithm restrictions for signed JAR files
|
||||
#
|
||||
# In some environments, certain algorithms or key lengths may be undesirable
|
||||
# for signed JAR validation. For example, "MD2" is generally no longer
|
||||
# considered to be a secure hash algorithm. This section describes the
|
||||
# mechanism for disabling algorithms based on algorithm name and/or key length.
|
||||
# JARs signed with any of the disabled algorithms or key sizes will be treated
|
||||
# as unsigned.
|
||||
#
|
||||
# The syntax of the disabled algorithm string is described as follows:
|
||||
# DisabledAlgorithms:
|
||||
# " DisabledAlgorithm { , DisabledAlgorithm } "
|
||||
#
|
||||
# DisabledAlgorithm:
|
||||
# AlgorithmName [Constraint]
|
||||
#
|
||||
# AlgorithmName:
|
||||
# (see below)
|
||||
#
|
||||
# Constraint:
|
||||
# KeySizeConstraint
|
||||
#
|
||||
# KeySizeConstraint:
|
||||
# keySize Operator KeyLength
|
||||
#
|
||||
# Operator:
|
||||
# <= | < | == | != | >= | >
|
||||
#
|
||||
# KeyLength:
|
||||
# Integer value of the algorithm's key length in bits
|
||||
#
|
||||
# Note: This property is currently used by the JDK Reference
|
||||
# implementation. It is not guaranteed to be examined and used by other
|
||||
# implementations.
|
||||
#
|
||||
jdk.jar.disabledAlgorithms=MD2, MD5, RSA keySize < 1024, \
|
||||
DSA keySize < 1024
|
||||
|
||||
# Algorithm restrictions for Secure Socket Layer/Transport Layer Security
|
||||
# (SSL/TLS/DTLS) processing
|
||||
#
|
||||
@ -936,41 +974,3 @@ jdk.xml.dsig.secureValidationPolicy=\
|
||||
#
|
||||
#jdk.serialFilter=pattern;pattern
|
||||
|
||||
# Algorithm restrictions for signed JAR files
|
||||
#
|
||||
# In some environments, certain algorithms or key lengths may be undesirable
|
||||
# for signed JAR validation. For example, "MD2" is generally no longer
|
||||
# considered to be a secure hash algorithm. This section describes the
|
||||
# mechanism for disabling algorithms based on algorithm name and/or key length.
|
||||
# JARs signed with any of the disabled algorithms or key sizes will be treated
|
||||
# as unsigned.
|
||||
#
|
||||
# The syntax of the disabled algorithm string is described as follows:
|
||||
# DisabledAlgorithms:
|
||||
# " DisabledAlgorithm { , DisabledAlgorithm } "
|
||||
#
|
||||
# DisabledAlgorithm:
|
||||
# AlgorithmName [Constraint]
|
||||
#
|
||||
# AlgorithmName:
|
||||
# (see below)
|
||||
#
|
||||
# Constraint:
|
||||
# KeySizeConstraint
|
||||
#
|
||||
# KeySizeConstraint:
|
||||
# keySize Operator KeyLength
|
||||
#
|
||||
# Operator:
|
||||
# <= | < | == | != | >= | >
|
||||
#
|
||||
# KeyLength:
|
||||
# Integer value of the algorithm's key length in bits
|
||||
#
|
||||
# Note: This property is currently used by the JDK Reference
|
||||
# implementation. It is not guaranteed to be examined and used by other
|
||||
# implementations.
|
||||
#
|
||||
jdk.jar.disabledAlgorithms=MD2, RSA keySize < 1024, \
|
||||
DSA keySize < 1024
|
||||
|
||||
|
||||
@ -111,11 +111,11 @@ grant codeBase "jrt:/jdk.crypto.ec" {
|
||||
grant codeBase "jrt:/jdk.crypto.pkcs11" {
|
||||
permission java.lang.RuntimePermission
|
||||
"accessClassInPackage.sun.security.*";
|
||||
permission java.lang.RuntimePermission "accessClassInPackage.sun.misc";
|
||||
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
|
||||
permission java.lang.RuntimePermission "loadLibrary.j2pkcs11";
|
||||
// needs "security.pkcs11.allowSingleThreadedModules"
|
||||
permission java.util.PropertyPermission "*", "read";
|
||||
permission java.util.PropertyPermission "sun.security.pkcs11.allowSingleThreadedModules", "read";
|
||||
permission java.util.PropertyPermission "os.name", "read";
|
||||
permission java.util.PropertyPermission "os.arch", "read";
|
||||
permission java.security.SecurityPermission "putProviderProperty.*";
|
||||
permission java.security.SecurityPermission "clearProviderProperties.*";
|
||||
permission java.security.SecurityPermission "removeProviderProperty.*";
|
||||
|
||||
@ -23,20 +23,19 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include "jni.h"
|
||||
#include "jvm.h"
|
||||
#include "jni_util.h"
|
||||
#include "net_util.h"
|
||||
|
||||
int IPv6_supported() ;
|
||||
int reuseport_supported() ;
|
||||
#include "java_net_InetAddress.h"
|
||||
|
||||
int IPv6_supported();
|
||||
int reuseport_supported();
|
||||
|
||||
static int IPv6_available;
|
||||
static int REUSEPORT_available;
|
||||
|
||||
JNIEXPORT jint JNICALL ipv6_available()
|
||||
{
|
||||
return IPv6_available ;
|
||||
return IPv6_available;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL reuseport_available()
|
||||
@ -206,11 +205,7 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
|
||||
jobject iaObj;
|
||||
#ifdef AF_INET6
|
||||
if (him->sa_family == AF_INET6) {
|
||||
#ifdef WIN32
|
||||
struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him;
|
||||
#else
|
||||
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
|
||||
#endif
|
||||
jbyte *caddr = (jbyte *)&(him6->sin6_addr);
|
||||
if (NET_IsIPv4Mapped(caddr)) {
|
||||
int address;
|
||||
@ -218,7 +213,7 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
|
||||
CHECK_NULL_RETURN(iaObj, NULL);
|
||||
address = NET_IPv4MappedToIPv4(caddr);
|
||||
setInetAddress_addr(env, iaObj, address);
|
||||
setInetAddress_family(env, iaObj, IPv4);
|
||||
setInetAddress_family(env, iaObj, java_net_InetAddress_IPv4);
|
||||
} else {
|
||||
jint scope;
|
||||
jboolean ret;
|
||||
@ -227,7 +222,7 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
|
||||
ret = setInet6Address_ipaddress(env, iaObj, (char *)&(him6->sin6_addr));
|
||||
if (ret == JNI_FALSE)
|
||||
return NULL;
|
||||
setInetAddress_family(env, iaObj, IPv6);
|
||||
setInetAddress_family(env, iaObj, java_net_InetAddress_IPv6);
|
||||
scope = getScopeID(him);
|
||||
setInet6Address_scopeid(env, iaObj, scope);
|
||||
}
|
||||
@ -238,7 +233,7 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
|
||||
struct sockaddr_in *him4 = (struct sockaddr_in *)him;
|
||||
iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
|
||||
CHECK_NULL_RETURN(iaObj, NULL);
|
||||
setInetAddress_family(env, iaObj, IPv4);
|
||||
setInetAddress_family(env, iaObj, java_net_InetAddress_IPv4);
|
||||
setInetAddress_addr(env, iaObj, ntohl(him4->sin_addr.s_addr));
|
||||
*port = ntohs(him4->sin_port);
|
||||
}
|
||||
@ -251,13 +246,10 @@ NET_SockaddrEqualsInetAddress(JNIEnv *env, struct sockaddr *him, jobject iaObj)
|
||||
jint family = AF_INET;
|
||||
|
||||
#ifdef AF_INET6
|
||||
family = getInetAddress_family(env, iaObj) == IPv4? AF_INET : AF_INET6;
|
||||
family = getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4 ?
|
||||
AF_INET : AF_INET6;
|
||||
if (him->sa_family == AF_INET6) {
|
||||
#ifdef WIN32
|
||||
struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him;
|
||||
#else
|
||||
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
|
||||
#endif
|
||||
jbyte *caddrNew = (jbyte *)&(him6->sin6_addr);
|
||||
if (NET_IsIPv4Mapped(caddrNew)) {
|
||||
int addrNew;
|
||||
|
||||
@ -36,12 +36,6 @@
|
||||
|
||||
#define MAX_PACKET_LEN 65536
|
||||
|
||||
#define IPv4 1
|
||||
#define IPv6 2
|
||||
|
||||
#define NET_ERROR(env, ex, msg) \
|
||||
{ if (!(*env)->ExceptionOccurred(env)) JNU_ThrowByName(env, ex, msg); }
|
||||
|
||||
#define NET_WAIT_READ 0x01
|
||||
#define NET_WAIT_WRITE 0x02
|
||||
#define NET_WAIT_CONNECT 0x04
|
||||
@ -127,45 +121,43 @@ JNIEXPORT void JNICALL Java_java_net_Inet6Address_init(JNIEnv *env, jclass cls);
|
||||
JNIEXPORT void JNICALL Java_java_net_NetworkInterface_init(JNIEnv *env, jclass cls);
|
||||
|
||||
JNIEXPORT void JNICALL NET_ThrowNew(JNIEnv *env, int errorNum, char *msg);
|
||||
|
||||
int NET_GetError();
|
||||
|
||||
void NET_ThrowCurrent(JNIEnv *env, char *msg);
|
||||
|
||||
jfieldID NET_GetFileDescriptorID(JNIEnv *env);
|
||||
|
||||
JNIEXPORT jint JNICALL ipv6_available() ;
|
||||
JNIEXPORT jint JNICALL ipv6_available();
|
||||
|
||||
JNIEXPORT jint JNICALL reuseport_available() ;
|
||||
JNIEXPORT jint JNICALL reuseport_available();
|
||||
|
||||
JNIEXPORT int JNICALL
|
||||
NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr *him, int *len, jboolean v4MappedAddress);
|
||||
NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port,
|
||||
struct sockaddr *him, int *len,
|
||||
jboolean v4MappedAddress);
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port);
|
||||
|
||||
void platformInit();
|
||||
|
||||
void parseExclusiveBindProperty(JNIEnv *env);
|
||||
|
||||
void
|
||||
NET_SetTrafficClass(struct sockaddr *him, int trafficClass);
|
||||
void NET_SetTrafficClass(struct sockaddr *him, int trafficClass);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
NET_GetPortFromSockaddr(struct sockaddr *him);
|
||||
JNIEXPORT jint JNICALL NET_GetPortFromSockaddr(struct sockaddr *him);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
NET_SockaddrEqualsInetAddress(JNIEnv *env,struct sockaddr *him, jobject iaObj);
|
||||
|
||||
int
|
||||
NET_IsIPv4Mapped(jbyte* caddr);
|
||||
int NET_IsIPv4Mapped(jbyte* caddr);
|
||||
|
||||
int
|
||||
NET_IPv4MappedToIPv4(jbyte* caddr);
|
||||
int NET_IPv4MappedToIPv4(jbyte* caddr);
|
||||
|
||||
int
|
||||
NET_IsEqual(jbyte* caddr1, jbyte* caddr2);
|
||||
int NET_IsEqual(jbyte* caddr1, jbyte* caddr2);
|
||||
|
||||
int
|
||||
NET_IsZeroAddr(jbyte* caddr);
|
||||
int NET_IsZeroAddr(jbyte* caddr);
|
||||
|
||||
/* Socket operations
|
||||
*
|
||||
@ -191,9 +183,9 @@ NET_MapSocketOptionV6(jint cmd, int *level, int *optname);
|
||||
JNIEXPORT jint JNICALL
|
||||
NET_EnableFastTcpLoopback(int fd);
|
||||
|
||||
int getScopeID (struct sockaddr *);
|
||||
int getScopeID(struct sockaddr *);
|
||||
|
||||
int cmpScopeID (unsigned int, struct sockaddr *);
|
||||
int cmpScopeID(unsigned int, struct sockaddr *);
|
||||
|
||||
unsigned short in_cksum(unsigned short *addr, int len);
|
||||
|
||||
|
||||
34
jdk/src/java.base/unix/conf/s390x/jvm.cfg
Normal file
34
jdk/src/java.base/unix/conf/s390x/jvm.cfg
Normal file
@ -0,0 +1,34 @@
|
||||
# Copyright (c) 2011, 2016, 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
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation. Oracle designates this
|
||||
# particular file as subject to the "Classpath" exception as provided
|
||||
# by Oracle in the LICENSE file that accompanied this code.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
# List of JVMs that can be used as an option to java, javac, etc.
|
||||
# Order is important -- first in this list is the default JVM.
|
||||
# NOTE that this both this file and its format are UNSUPPORTED and
|
||||
# WILL GO AWAY in a future release.
|
||||
#
|
||||
# You may also select a JVM in an arbitrary location with the
|
||||
# "-XXaltjvm=<jvm_dir>" option, but that too is unsupported
|
||||
# and may not be available in a future release.
|
||||
#
|
||||
-server KNOWN
|
||||
-client IGNORE
|
||||
@ -22,27 +22,17 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifdef _ALLBSD_SOURCE
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#include "jvm.h"
|
||||
#include "jni_util.h"
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_Inet4AddressImpl.h"
|
||||
@ -293,13 +283,12 @@ Java_java_net_Inet4AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
|
||||
addr |= ((caddr[2] <<8) & 0xff00);
|
||||
addr |= (caddr[3] & 0xff);
|
||||
memset((char *) &him4, 0, sizeof(him4));
|
||||
him4.sin_addr.s_addr = (uint32_t) htonl(addr);
|
||||
him4.sin_addr.s_addr = htonl(addr);
|
||||
him4.sin_family = AF_INET;
|
||||
sa = (struct sockaddr *) &him4;
|
||||
len = sizeof(him4);
|
||||
|
||||
error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0,
|
||||
NI_NAMEREQD);
|
||||
error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
|
||||
|
||||
if (!error) {
|
||||
ret = (*env)->NewStringUTF(env, host);
|
||||
@ -443,7 +432,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
|
||||
|
||||
if (!skip) {
|
||||
struct addrinfo *next
|
||||
= (struct addrinfo*) malloc(sizeof(struct addrinfo));
|
||||
= (struct addrinfo *)malloc(sizeof(struct addrinfo));
|
||||
if (!next) {
|
||||
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
|
||||
ret = NULL;
|
||||
@ -528,13 +517,12 @@ Java_java_net_Inet4AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
|
||||
addr |= ((caddr[2] <<8) & 0xff00);
|
||||
addr |= (caddr[3] & 0xff);
|
||||
memset((void *) &him4, 0, sizeof(him4));
|
||||
him4.sin_addr.s_addr = (uint32_t) htonl(addr);
|
||||
him4.sin_addr.s_addr = htonl(addr);
|
||||
him4.sin_family = AF_INET;
|
||||
sa = (struct sockaddr *) &him4;
|
||||
len = sizeof(him4);
|
||||
|
||||
error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0,
|
||||
NI_NAMEREQD);
|
||||
error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
|
||||
|
||||
if (!error) {
|
||||
ret = (*env)->NewStringUTF(env, host);
|
||||
|
||||
@ -22,29 +22,21 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#ifdef MACOSX
|
||||
#include <netinet/icmp6.h>
|
||||
|
||||
#if defined(_ALLBSD_SOURCE)
|
||||
#include <ifaddrs.h>
|
||||
#include <net/if.h>
|
||||
#include <unistd.h> /* gethostname */
|
||||
#endif
|
||||
|
||||
#include "jvm.h"
|
||||
#include "jni_util.h"
|
||||
#include "net_util.h"
|
||||
#ifndef IPV6_DEFS_H
|
||||
#include <netinet/icmp6.h>
|
||||
#endif
|
||||
|
||||
#include "java_net_Inet4AddressImpl.h"
|
||||
#include "java_net_Inet6AddressImpl.h"
|
||||
@ -504,24 +496,23 @@ Java_java_net_Inet6AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
|
||||
addr |= ((caddr[2] <<8) & 0xff00);
|
||||
addr |= (caddr[3] & 0xff);
|
||||
memset((void *) &him4, 0, sizeof(him4));
|
||||
him4.sin_addr.s_addr = (uint32_t) htonl(addr);
|
||||
him4.sin_addr.s_addr = htonl(addr);
|
||||
him4.sin_family = AF_INET;
|
||||
sa = (struct sockaddr *) &him4;
|
||||
sa = (struct sockaddr *)&him4;
|
||||
len = sizeof(him4);
|
||||
} else {
|
||||
/*
|
||||
* For IPv6 address construct a sockaddr_in6 structure.
|
||||
*/
|
||||
(*env)->GetByteArrayRegion(env, addrArray, 0, 16, caddr);
|
||||
memset((void *) &him6, 0, sizeof(him6));
|
||||
memcpy((void *)&(him6.sin6_addr), caddr, sizeof(struct in6_addr) );
|
||||
memset((void *)&him6, 0, sizeof(him6));
|
||||
memcpy((void *)&(him6.sin6_addr), caddr, sizeof(struct in6_addr));
|
||||
him6.sin6_family = AF_INET6;
|
||||
sa = (struct sockaddr *) &him6 ;
|
||||
len = sizeof(him6) ;
|
||||
sa = (struct sockaddr *)&him6;
|
||||
len = sizeof(him6);
|
||||
}
|
||||
|
||||
error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0,
|
||||
NI_NAMEREQD);
|
||||
error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
|
||||
|
||||
if (!error) {
|
||||
ret = (*env)->NewStringUTF(env, host);
|
||||
|
||||
@ -22,55 +22,36 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <strings.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_arp.h>
|
||||
|
||||
#if defined(__solaris__)
|
||||
#include <sys/dlpi.h>
|
||||
#include <fcntl.h>
|
||||
#include <stropts.h>
|
||||
#include <sys/sockio.h>
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined(_AIX)
|
||||
#include <sys/ioctl.h>
|
||||
#include <netinet/in6_var.h>
|
||||
#include <sys/ndd_var.h>
|
||||
#include <sys/kinfo.h>
|
||||
#endif
|
||||
|
||||
#if defined(_ALLBSD_SOURCE)
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#if defined(__solaris__)
|
||||
#include <stropts.h>
|
||||
#include <sys/dlpi.h>
|
||||
#include <sys/sockio.h>
|
||||
#if defined(__APPLE__)
|
||||
#include <net/ethernet.h>
|
||||
#include <net/if_var.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <netinet/in_var.h>
|
||||
#include <ifaddrs.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "jvm.h"
|
||||
#include "jni_util.h"
|
||||
#if defined(_ALLBSD_SOURCE)
|
||||
#include <net/ethernet.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <ifaddrs.h>
|
||||
#endif
|
||||
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_InetAddress.h"
|
||||
|
||||
#if defined(__linux__)
|
||||
#define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6"
|
||||
#elif defined(__solaris__)
|
||||
@ -332,7 +313,7 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
|
||||
{
|
||||
netif *ifs, *curr;
|
||||
#if defined(AF_INET6)
|
||||
int family = (getInetAddress_family(env, iaObj) == IPv4) ? AF_INET : AF_INET6;
|
||||
int family = (getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4) ? AF_INET : AF_INET6;
|
||||
#else
|
||||
int family = AF_INET;
|
||||
#endif
|
||||
|
||||
@ -22,29 +22,23 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#ifdef __solaris__
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stropts.h>
|
||||
#if defined(__solaris__)
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_PlainDatagramSocketImpl.h"
|
||||
#include "java_net_InetAddress.h"
|
||||
#include "java_net_NetworkInterface.h"
|
||||
#include "java_net_SocketOptions.h"
|
||||
|
||||
#ifndef BSD_COMP
|
||||
#define BSD_COMP
|
||||
#endif
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
#include <unistd.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <netinet/ip.h>
|
||||
|
||||
#define IPV6_MULTICAST_IF 17
|
||||
#ifndef SO_BSDCOMPAT
|
||||
#define SO_BSDCOMPAT 14
|
||||
@ -58,7 +52,11 @@
|
||||
#endif
|
||||
#endif // __linux__
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef __solaris__
|
||||
#ifndef BSD_COMP
|
||||
#define BSD_COMP
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef IPTOS_TOS_MASK
|
||||
#define IPTOS_TOS_MASK 0x1e
|
||||
@ -67,12 +65,6 @@
|
||||
#define IPTOS_PREC_MASK 0xe0
|
||||
#endif
|
||||
|
||||
#include "jvm.h"
|
||||
#include "jni_util.h"
|
||||
#include "net_util.h"
|
||||
#include "java_net_SocketOptions.h"
|
||||
#include "java_net_PlainDatagramSocketImpl.h"
|
||||
#include "java_net_NetworkInterface.h"
|
||||
/************************************************************************
|
||||
* PlainDatagramSocketImpl
|
||||
*/
|
||||
@ -151,9 +143,6 @@ static int getFD(JNIEnv *env, jobject this) {
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_net_PlainDatagramSocketImpl_init(JNIEnv *env, jclass cls) {
|
||||
|
||||
#ifdef __linux__
|
||||
struct utsname sysinfo;
|
||||
#endif
|
||||
pdsi_fdID = (*env)->GetFieldID(env, cls, "fd",
|
||||
"Ljava/io/FileDescriptor;");
|
||||
CHECK_NULL(pdsi_fdID);
|
||||
@ -550,7 +539,8 @@ Java_java_net_PlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
|
||||
|
||||
iaObj = NET_SockaddrToInetAddress(env, &rmtaddr.sa, &port);
|
||||
#ifdef AF_INET6
|
||||
family = getInetAddress_family(env, iaObj) == IPv4? AF_INET : AF_INET6;
|
||||
family = getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4 ?
|
||||
AF_INET : AF_INET6;
|
||||
#else
|
||||
family = AF_INET;
|
||||
#endif
|
||||
@ -1071,7 +1061,7 @@ static void mcast_set_if_by_if_v4(JNIEnv *env, jobject this, int fd, jobject val
|
||||
*/
|
||||
for (i = 0; i < len; i++) {
|
||||
addr = (*env)->GetObjectArrayElement(env, addrArray, i);
|
||||
if (getInetAddress_family(env, addr) == IPv4) {
|
||||
if (getInetAddress_family(env, addr) == java_net_InetAddress_IPv4) {
|
||||
in.s_addr = htonl(getInetAddress_addr(env, addr));
|
||||
break;
|
||||
}
|
||||
@ -1970,7 +1960,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
|
||||
ipv6_join_leave = ipv6_available();
|
||||
|
||||
#ifdef __linux__
|
||||
if (getInetAddress_family(env, iaObj) == IPv4) {
|
||||
if (getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4) {
|
||||
ipv6_join_leave = JNI_FALSE;
|
||||
}
|
||||
#endif
|
||||
@ -2162,7 +2152,8 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
|
||||
jbyte caddr[16];
|
||||
jint family;
|
||||
jint address;
|
||||
family = getInetAddress_family(env, iaObj) == IPv4? AF_INET : AF_INET6;
|
||||
family = getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4 ?
|
||||
AF_INET : AF_INET6;
|
||||
if (family == AF_INET) { /* will convert to IPv4-mapped address */
|
||||
memset((char *) caddr, 0, 16);
|
||||
address = getInetAddress_addr(env, iaObj);
|
||||
|
||||
@ -22,32 +22,8 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#if defined(__linux__)
|
||||
#include <sys/poll.h>
|
||||
#endif
|
||||
#include <netinet/tcp.h> /* Defines TCP_NODELAY, needed for 2.6 */
|
||||
#include <netinet/in.h>
|
||||
#ifdef __linux__
|
||||
#include <netinet/ip.h>
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __solaris__
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
#include <unistd.h>
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
#include "jvm.h"
|
||||
#include "jni_util.h"
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_SocketOptions.h"
|
||||
|
||||
@ -22,20 +22,15 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "jvm.h"
|
||||
#include "jni_util.h"
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_SocketInputStream.h"
|
||||
|
||||
/************************************************************************
|
||||
/*
|
||||
* SocketInputStream
|
||||
*/
|
||||
|
||||
|
||||
@ -22,15 +22,10 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "jni_util.h"
|
||||
#include "jvm.h"
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_SocketOutputStream.h"
|
||||
|
||||
@ -22,59 +22,41 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/tcp.h> /* Defines TCP_NODELAY, needed for 2.6 */
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/tcp.h> // defines TCP_NODELAY
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifndef _ALLBSD_SOURCE
|
||||
#include <values.h>
|
||||
#else
|
||||
#include <limits.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifndef MAXINT
|
||||
#define MAXINT INT_MAX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __solaris__
|
||||
#include <sys/filio.h>
|
||||
#include <sys/sockio.h>
|
||||
#include <stropts.h>
|
||||
#include <inet/nd.h>
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sys/ioctl.h>
|
||||
#if defined(__linux__)
|
||||
#include <arpa/inet.h>
|
||||
#include <net/route.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#ifndef IPV6_FLOWINFO_SEND
|
||||
#define IPV6_FLOWINFO_SEND 33
|
||||
#endif
|
||||
|
||||
#if defined(__solaris__)
|
||||
#include <inet/nd.h>
|
||||
#include <limits.h>
|
||||
#include <stropts.h>
|
||||
#include <sys/filio.h>
|
||||
#include <sys/sockio.h>
|
||||
#endif
|
||||
|
||||
#ifdef _AIX
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
#include "jni_util.h"
|
||||
#include "jvm.h"
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_SocketOptions.h"
|
||||
#include "java_net_InetAddress.h"
|
||||
|
||||
#if defined(__linux__) && !defined(IPV6_FLOWINFO_SEND)
|
||||
#define IPV6_FLOWINFO_SEND 33
|
||||
#endif
|
||||
|
||||
#if defined(__solaris__) && !defined(MAXINT)
|
||||
#define MAXINT INT_MAX
|
||||
#endif
|
||||
|
||||
/*
|
||||
* EXCLBIND socket options only on Solaris
|
||||
@ -806,13 +788,15 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
|
||||
family = getInetAddress_family(env, iaObj);
|
||||
#ifdef AF_INET6
|
||||
/* needs work. 1. family 2. clean up him6 etc deallocate memory */
|
||||
if (ipv6_available() && !(family == IPv4 && v4MappedAddress == JNI_FALSE)) {
|
||||
if (ipv6_available() && !(family == java_net_InetAddress_IPv4 &&
|
||||
v4MappedAddress == JNI_FALSE)) {
|
||||
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
|
||||
jbyte caddr[16];
|
||||
jint address;
|
||||
|
||||
|
||||
if (family == IPv4) { /* will convert to IPv4-mapped address */
|
||||
if (family == java_net_InetAddress_IPv4) {
|
||||
// convert to IPv4-mapped address
|
||||
memset((char *) caddr, 0, 16);
|
||||
address = getInetAddress_addr(env, iaObj);
|
||||
if (address == INADDR_ANY) {
|
||||
@ -906,7 +890,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
|
||||
#else
|
||||
/* handle scope_id for solaris */
|
||||
|
||||
if (family != IPv4) {
|
||||
if (family != java_net_InetAddress_IPv4) {
|
||||
if (ia6_scopeidID) {
|
||||
him6->sin6_scope_id = getInet6Address_scopeid(env, iaObj);
|
||||
}
|
||||
@ -917,14 +901,14 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
|
||||
{
|
||||
struct sockaddr_in *him4 = (struct sockaddr_in*)him;
|
||||
jint address;
|
||||
if (family == IPv6) {
|
||||
if (family == java_net_InetAddress_IPv6) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Protocol family unavailable");
|
||||
return -1;
|
||||
}
|
||||
memset((char *) him4, 0, sizeof(struct sockaddr_in));
|
||||
address = getInetAddress_addr(env, iaObj);
|
||||
him4->sin_port = htons((short) port);
|
||||
him4->sin_addr.s_addr = (uint32_t) htonl(address);
|
||||
him4->sin_addr.s_addr = htonl(address);
|
||||
him4->sin_family = AF_INET;
|
||||
*len = sizeof(struct sockaddr_in);
|
||||
}
|
||||
|
||||
@ -26,13 +26,9 @@
|
||||
#ifndef NET_UTILS_MD_H
|
||||
#define NET_UTILS_MD_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/poll.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
int NET_Timeout(int s, long timeout);
|
||||
int NET_Timeout0(int s, long timeout, long currentTime);
|
||||
|
||||
@ -22,10 +22,8 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include "jni.h"
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_DualStackPlainDatagramSocketImpl.h"
|
||||
|
||||
/*
|
||||
|
||||
@ -22,11 +22,10 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include "jni.h"
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_DualStackPlainSocketImpl.h"
|
||||
#include "java_net_SocketOptions.h"
|
||||
|
||||
#define SET_BLOCKING 0
|
||||
#define SET_NONBLOCKING 1
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2016, 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
|
||||
@ -22,24 +22,12 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/types.h>
|
||||
#include <process.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <icmpapi.h>
|
||||
#include <WinError.h>
|
||||
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_InetAddress.h"
|
||||
#include "java_net_Inet4AddressImpl.h"
|
||||
#include "net_util.h"
|
||||
#include "icmp.h"
|
||||
|
||||
|
||||
/*
|
||||
* Returns true if hostname is in dotted IP address format. Note that this
|
||||
|
||||
@ -22,38 +22,13 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/types.h>
|
||||
#include <process.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <icmpapi.h>
|
||||
|
||||
#include "net_util.h"
|
||||
|
||||
#include "java_net_InetAddress.h"
|
||||
#include "java_net_Inet4AddressImpl.h"
|
||||
#include "java_net_Inet6AddressImpl.h"
|
||||
#include "net_util.h"
|
||||
#include "icmp.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#ifndef _WIN64
|
||||
|
||||
/* Retain this code a little longer to support building in
|
||||
* old environments. _MSC_VER is defined as:
|
||||
* 1200 for MSVC++ 6.0
|
||||
* 1310 for Vc7
|
||||
*/
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1310
|
||||
#define sockaddr_in6 SOCKADDR_IN6
|
||||
#endif
|
||||
#endif
|
||||
#define uint32_t UINT32
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Inet6AddressImpl
|
||||
@ -300,7 +275,7 @@ Java_java_net_Inet6AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
|
||||
addr |= ((caddr[2] <<8) & 0xff00);
|
||||
addr |= (caddr[3] & 0xff);
|
||||
memset((char *) &him4, 0, sizeof(him4));
|
||||
him4.sin_addr.s_addr = (uint32_t) htonl(addr);
|
||||
him4.sin_addr.s_addr = htonl(addr);
|
||||
him4.sin_family = AF_INET;
|
||||
sa = (struct sockaddr *) &him4;
|
||||
len = sizeof(him4);
|
||||
|
||||
@ -22,17 +22,10 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <winsock2.h> /* needed for htonl */
|
||||
#include <iprtrmib.h>
|
||||
#include <assert.h>
|
||||
#include "net_util.h"
|
||||
#include "NetworkInterface.h"
|
||||
|
||||
#include "java_net_NetworkInterface.h"
|
||||
#include "jni_util.h"
|
||||
|
||||
#include "NetworkInterface.h"
|
||||
|
||||
/*
|
||||
* Windows implementation of the java.net.NetworkInterface native methods.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2016, 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,7 +26,6 @@
|
||||
#ifndef NETWORK_INTERFACE_H
|
||||
#define NETWORK_INTERFACE_H
|
||||
|
||||
#include <iphlpapi.h>
|
||||
#include "net_util.h"
|
||||
|
||||
/*
|
||||
|
||||
@ -22,19 +22,10 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <winsock2.h> /* needed for htonl */
|
||||
#include <iprtrmib.h>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include "net_util.h"
|
||||
#include "NetworkInterface.h"
|
||||
|
||||
#include "java_net_NetworkInterface.h"
|
||||
#include "jni_util.h"
|
||||
|
||||
#include "NetworkInterface.h"
|
||||
#include "net_util.h"
|
||||
|
||||
/*
|
||||
* Windows implementation of the java.net.NetworkInterface native methods.
|
||||
@ -554,14 +545,20 @@ static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs)
|
||||
* Create a NetworkInterface object and populate it
|
||||
*/
|
||||
netifObj = (*env)->NewObject(env, ni_class, ni_ctor);
|
||||
if (netifObj == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
name = (*env)->NewStringUTF(env, ifs->name);
|
||||
if (name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (ifs->dNameIsUnicode) {
|
||||
displayName = (*env)->NewString(env, (PWCHAR)ifs->displayName,
|
||||
(jsize)wcslen ((PWCHAR)ifs->displayName));
|
||||
} else {
|
||||
displayName = (*env)->NewStringUTF(env, ifs->displayName);
|
||||
}
|
||||
if (netifObj == NULL || name == NULL || displayName == NULL) {
|
||||
if (displayName == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(*env)->SetObjectField(env, netifObj, ni_nameID, name);
|
||||
@ -621,26 +618,28 @@ static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs)
|
||||
(*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
|
||||
} else /* AF_INET6 */ {
|
||||
int scope;
|
||||
jboolean ret;
|
||||
iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
|
||||
if (iaObj) {
|
||||
jboolean ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.sa6.sin6_addr.s6_addr));
|
||||
if (ret == JNI_FALSE) {
|
||||
return NULL;
|
||||
}
|
||||
scope = addrs->addr.sa6.sin6_scope_id;
|
||||
if (scope != 0) { /* zero is default value, no need to set */
|
||||
setInet6Address_scopeid(env, iaObj, scope);
|
||||
setInet6Address_scopeifname(env, iaObj, netifObj);
|
||||
}
|
||||
ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
|
||||
if (ibObj == NULL) {
|
||||
free_netaddr(netaddrP);
|
||||
return NULL;
|
||||
}
|
||||
(*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
|
||||
(*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
|
||||
(*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
|
||||
if (iaObj == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.sa6.sin6_addr.s6_addr));
|
||||
if (ret == JNI_FALSE) {
|
||||
return NULL;
|
||||
}
|
||||
scope = addrs->addr.sa6.sin6_scope_id;
|
||||
if (scope != 0) { /* zero is default value, no need to set */
|
||||
setInet6Address_scopeid(env, iaObj, scope);
|
||||
setInet6Address_scopeifname(env, iaObj, netifObj);
|
||||
}
|
||||
ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
|
||||
if (ibObj == NULL) {
|
||||
free_netaddr(netaddrP);
|
||||
return NULL;
|
||||
}
|
||||
(*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
|
||||
(*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
|
||||
(*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
|
||||
}
|
||||
(*env)->SetObjectArrayElement(env, addrArr, addr_index, iaObj);
|
||||
addrs = addrs->next;
|
||||
|
||||
@ -22,24 +22,15 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "java_net_SocketInputStream.h"
|
||||
|
||||
#include "net_util.h"
|
||||
#include "jni_util.h"
|
||||
|
||||
#include "java_net_SocketInputStream.h"
|
||||
|
||||
/*************************************************************************
|
||||
* SocketInputStream
|
||||
*/
|
||||
|
||||
static jfieldID IO_fd_fdID;
|
||||
|
||||
/*
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2016, 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
|
||||
@ -22,19 +22,11 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "java_net_SocketOutputStream.h"
|
||||
|
||||
#include "net_util.h"
|
||||
#include "jni_util.h"
|
||||
|
||||
#include "java_net_SocketOutputStream.h"
|
||||
|
||||
/************************************************************************
|
||||
* SocketOutputStream
|
||||
|
||||
@ -22,15 +22,15 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "net_util.h"
|
||||
#include "NetworkInterface.h"
|
||||
|
||||
#include "java_net_TwoStacksPlainDatagramSocketImpl.h"
|
||||
#include "java_net_SocketOptions.h"
|
||||
#include "java_net_NetworkInterface.h"
|
||||
#include "java_net_InetAddress.h"
|
||||
|
||||
#ifndef IPTOS_TOS_MASK
|
||||
#define IPTOS_TOS_MASK 0x1e
|
||||
@ -39,14 +39,6 @@
|
||||
#define IPTOS_PREC_MASK 0xe0
|
||||
#endif
|
||||
|
||||
#include "java_net_TwoStacksPlainDatagramSocketImpl.h"
|
||||
#include "java_net_SocketOptions.h"
|
||||
#include "java_net_NetworkInterface.h"
|
||||
|
||||
#include "NetworkInterface.h"
|
||||
#include "jvm.h"
|
||||
#include "jni_util.h"
|
||||
#include "net_util.h"
|
||||
|
||||
#define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
|
||||
#define IN_MULTICAST(i) IN_CLASSD(i)
|
||||
@ -439,7 +431,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_bind0(JNIEnv *env, jobject this,
|
||||
memset((char *)&lcladdr, 0, sizeof(lcladdr));
|
||||
|
||||
family = getInetAddress_family(env, addressObj);
|
||||
if (family == IPv6 && !ipv6_supported) {
|
||||
if (family == java_net_InetAddress_IPv6 && !ipv6_supported) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
||||
"Protocol family not supported");
|
||||
return;
|
||||
@ -561,13 +553,13 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_connect0(JNIEnv *env, jobject thi
|
||||
addr = getInetAddress_addr(env, address);
|
||||
|
||||
family = getInetAddress_family(env, address);
|
||||
if (family == IPv6 && !ipv6_supported) {
|
||||
if (family == java_net_InetAddress_IPv6 && !ipv6_supported) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
||||
"Protocol family not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
fdc = family == IPv4? fd: fd1;
|
||||
fdc = family == java_net_InetAddress_IPv4 ? fd : fd1;
|
||||
|
||||
if (xp_or_later) {
|
||||
/* SIO_UDP_CONNRESET fixes a bug introduced in Windows 2000, which
|
||||
@ -605,12 +597,12 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_disconnect0(JNIEnv *env, jobject
|
||||
jint fd, len;
|
||||
SOCKETADDRESS addr;
|
||||
|
||||
if (family == IPv4) {
|
||||
if (family == java_net_InetAddress_IPv4) {
|
||||
fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
|
||||
len = sizeof (struct sockaddr_in);
|
||||
len = sizeof(struct sockaddr_in);
|
||||
} else {
|
||||
fdObj = (*env)->GetObjectField(env, this, pdsi_fd1ID);
|
||||
len = sizeof (struct SOCKADDR_IN6);
|
||||
len = sizeof(struct sockaddr_in6);
|
||||
}
|
||||
|
||||
if (IS_NULL(fdObj)) {
|
||||
@ -678,7 +670,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_send(JNIEnv *env, jobject this,
|
||||
}
|
||||
|
||||
family = getInetAddress_family(env, iaObj);
|
||||
if (family == IPv4) {
|
||||
if (family == java_net_InetAddress_IPv4) {
|
||||
fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
|
||||
} else {
|
||||
if (!ipv6_available()) {
|
||||
@ -830,6 +822,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
|
||||
}
|
||||
if (IS_NULL(addressObj)) {
|
||||
JNU_ThrowNullPointerException(env, "Null address in peek()");
|
||||
return -1;
|
||||
} else {
|
||||
address = getInetAddress_addr(env, addressObj);
|
||||
/* We only handle IPv4 for now. Will support IPv6 once its in the os */
|
||||
@ -905,7 +898,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
|
||||
return 0;
|
||||
}
|
||||
setInetAddress_addr(env, addressObj, ntohl(remote_addr.sa4.sin_addr.s_addr));
|
||||
setInetAddress_family(env, addressObj, IPv4);
|
||||
setInetAddress_family(env, addressObj, java_net_InetAddress_IPv4);
|
||||
|
||||
/* return port */
|
||||
return ntohs(remote_addr.sa4.sin_port);
|
||||
@ -1127,11 +1120,23 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_peekData(JNIEnv *env, jobject thi
|
||||
}
|
||||
if (n == -1) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "socket closed");
|
||||
if (packetBufferLen > MAX_BUFFER_LEN) {
|
||||
free(fullPacket);
|
||||
}
|
||||
return -1;
|
||||
} else if (n == -2) {
|
||||
JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
|
||||
"operation interrupted");
|
||||
if (packetBufferLen > MAX_BUFFER_LEN) {
|
||||
free(fullPacket);
|
||||
}
|
||||
return -1;
|
||||
} else if (n < 0) {
|
||||
NET_ThrowCurrent(env, "Datagram receive failed");
|
||||
if (packetBufferLen > MAX_BUFFER_LEN) {
|
||||
free(fullPacket);
|
||||
}
|
||||
return -1;
|
||||
} else {
|
||||
jobject packetAddress;
|
||||
|
||||
@ -1597,7 +1602,7 @@ static int getInet4AddrFromIf (JNIEnv *env, jobject nif, struct in_addr *iaddr)
|
||||
{
|
||||
jobject addr;
|
||||
|
||||
int ret = getInetAddrFromIf (env, IPv4, nif, &addr);
|
||||
int ret = getInetAddrFromIf(env, java_net_InetAddress_IPv4, nif, &addr);
|
||||
if (ret == -1) {
|
||||
return -1;
|
||||
}
|
||||
@ -1882,7 +1887,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_socketNativeSetOption
|
||||
default :
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
||||
"Socket option not supported by PlainDatagramSocketImp");
|
||||
break;
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
@ -2272,9 +2277,9 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_socketLocalAddress
|
||||
len = sizeof(struct sockaddr_in);
|
||||
|
||||
/* family==-1 when socket is not connected */
|
||||
if ((family == IPv6) || (family == -1 && fd == -1)) {
|
||||
if ((family == java_net_InetAddress_IPv6) || (family == -1 && fd == -1)) {
|
||||
fd = fd1; /* must be IPv6 only */
|
||||
len = sizeof (struct SOCKADDR_IN6);
|
||||
len = sizeof(struct sockaddr_in6);
|
||||
}
|
||||
|
||||
if (fd == -1) {
|
||||
@ -2325,6 +2330,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_setTimeToLive(JNIEnv *env, jobjec
|
||||
if (NET_SetSockOpt(fd, IPPROTO_IP, IP_MULTICAST_TTL, (char*)&ittl,
|
||||
sizeof (ittl)) < 0) {
|
||||
NET_ThrowCurrent(env, "set IP_MULTICAST_TTL failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2518,6 +2524,9 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
|
||||
} else {
|
||||
ifindex = getIndexFromIf (env, niObj);
|
||||
if (ifindex == -1) {
|
||||
if ((*env)->ExceptionOccurred(env)) {
|
||||
return;
|
||||
}
|
||||
NET_ThrowCurrent(env, "get ifindex failed");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -22,23 +22,13 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "java_net_SocketOptions.h"
|
||||
#include "java_net_TwoStacksPlainSocketImpl.h"
|
||||
#include "java_net_InetAddress.h"
|
||||
#include "java_io_FileDescriptor.h"
|
||||
#include "java_lang_Integer.h"
|
||||
|
||||
#include "net_util.h"
|
||||
#include "jni_util.h"
|
||||
|
||||
#include "java_net_TwoStacksPlainSocketImpl.h"
|
||||
#include "java_net_SocketOptions.h"
|
||||
#include "java_net_InetAddress.h"
|
||||
|
||||
/************************************************************************
|
||||
* TwoStacksPlainSocketImpl
|
||||
@ -108,7 +98,7 @@ Java_java_net_TwoStacksPlainSocketImpl_initProto(JNIEnv *env, jclass cls) {
|
||||
psi_portID = (*env)->GetFieldID(env, cls, "port", "I");
|
||||
CHECK_NULL(psi_portID);
|
||||
psi_lastfdID = (*env)->GetFieldID(env, cls, "lastfd", "I");
|
||||
CHECK_NULL(psi_portID);
|
||||
CHECK_NULL(psi_lastfdID);
|
||||
psi_localportID = (*env)->GetFieldID(env, cls, "localport", "I");
|
||||
CHECK_NULL(psi_localportID);
|
||||
psi_timeoutID = (*env)->GetFieldID(env, cls, "timeout", "I");
|
||||
@ -153,17 +143,17 @@ Java_java_net_TwoStacksPlainSocketImpl_socketCreate(JNIEnv *env, jobject this,
|
||||
fd1Obj = (*env)->GetObjectField(env, this, psi_fd1ID);
|
||||
|
||||
if (IS_NULL(fd1Obj)) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
||||
"null fd1 object");
|
||||
(*env)->SetIntField(env, fdObj, IO_fd_fdID, -1);
|
||||
NET_SocketClose(fd);
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
||||
"null fd1 object");
|
||||
return;
|
||||
}
|
||||
fd1 = socket(AF_INET6, (stream ? SOCK_STREAM: SOCK_DGRAM), 0);
|
||||
if (fd1 == -1) {
|
||||
NET_ThrowCurrent(env, "create");
|
||||
(*env)->SetIntField(env, fdObj, IO_fd_fdID, -1);
|
||||
NET_SocketClose(fd);
|
||||
NET_ThrowCurrent(env, "create");
|
||||
return;
|
||||
} else {
|
||||
/* Set socket attribute so it is not passed to any child process */
|
||||
@ -413,7 +403,7 @@ Java_java_net_TwoStacksPlainSocketImpl_socketBind(JNIEnv *env, jobject this,
|
||||
|
||||
family = getInetAddress_family(env, iaObj);
|
||||
|
||||
if (family == IPv6 && !ipv6_supported) {
|
||||
if (family == java_net_InetAddress_IPv6 && !ipv6_supported) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
||||
"Protocol family not supported");
|
||||
return;
|
||||
@ -655,18 +645,18 @@ Java_java_net_TwoStacksPlainSocketImpl_socketAccept(JNIEnv *env, jobject this,
|
||||
return;
|
||||
}
|
||||
if (fd2 == fd) { /* v4 */
|
||||
len = sizeof (struct sockaddr_in);
|
||||
len = sizeof(struct sockaddr_in);
|
||||
} else {
|
||||
len = sizeof (struct SOCKADDR_IN6);
|
||||
len = sizeof(struct sockaddr_in6);
|
||||
}
|
||||
fd = fd2;
|
||||
} else {
|
||||
int ret;
|
||||
if (fd1 != -1) {
|
||||
fd = fd1;
|
||||
len = sizeof (struct SOCKADDR_IN6);
|
||||
len = sizeof(struct sockaddr_in6);
|
||||
} else {
|
||||
len = sizeof (struct sockaddr_in);
|
||||
len = sizeof(struct sockaddr_in);
|
||||
}
|
||||
if (timeout) {
|
||||
ret = NET_Timeout(fd, timeout);
|
||||
@ -728,7 +718,7 @@ Java_java_net_TwoStacksPlainSocketImpl_socketAccept(JNIEnv *env, jobject this,
|
||||
}
|
||||
|
||||
setInetAddress_addr(env, socketAddressObj, ntohl(him.sa4.sin_addr.s_addr));
|
||||
setInetAddress_family(env, socketAddressObj, IPv4);
|
||||
setInetAddress_family(env, socketAddressObj, java_net_InetAddress_IPv4);
|
||||
(*env)->SetObjectField(env, socket, psi_addressID, socketAddressObj);
|
||||
} else {
|
||||
/* AF_INET6 -> Inet6Address */
|
||||
@ -754,7 +744,7 @@ Java_java_net_TwoStacksPlainSocketImpl_socketAccept(JNIEnv *env, jobject this,
|
||||
return;
|
||||
}
|
||||
setInet6Address_ipaddress(env, socketAddressObj, (char *)&him.sa6.sin6_addr);
|
||||
setInetAddress_family(env, socketAddressObj, IPv6);
|
||||
setInetAddress_family(env, socketAddressObj, java_net_InetAddress_IPv6);
|
||||
setInet6Address_scopeid(env, socketAddressObj, him.sa6.sin6_scope_id);
|
||||
|
||||
}
|
||||
@ -907,6 +897,7 @@ Java_java_net_TwoStacksPlainSocketImpl_socketNativeSetOption
|
||||
isRcvTimeoutSupported = JNI_FALSE;
|
||||
} else {
|
||||
NET_ThrowCurrent(env, "setsockopt SO_RCVTIMEO");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (fd1 != -1) {
|
||||
|
||||
@ -1,148 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2013, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#ifndef ICMP_H
|
||||
#define ICMP_H
|
||||
|
||||
/*
|
||||
* Structure of an internet header, naked of options.
|
||||
*
|
||||
* We declare ip_len and ip_off to be short, rather than ushort_t
|
||||
* pragmatically since otherwise unsigned comparisons can result
|
||||
* against negative integers quite easily, and fail in subtle ways.
|
||||
*/
|
||||
struct ip {
|
||||
unsigned char ip_hl:4, /* header length */
|
||||
ip_v:4; /* version */
|
||||
unsigned char ip_tos; /* type of service */
|
||||
short ip_len; /* total length */
|
||||
unsigned short ip_id; /* identification */
|
||||
short ip_off; /* fragment offset field */
|
||||
#define IP_DF 0x4000 /* don't fragment flag */
|
||||
#define IP_MF 0x2000 /* more fragments flag */
|
||||
unsigned char ip_ttl; /* time to live */
|
||||
unsigned char ip_p; /* protocol */
|
||||
unsigned short ip_sum; /* checksum */
|
||||
struct in_addr ip_src, ip_dst; /* source and dest address */
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure of an icmp header.
|
||||
*/
|
||||
struct icmp {
|
||||
unsigned char icmp_type; /* type of message, see below */
|
||||
unsigned char icmp_code; /* type sub code */
|
||||
unsigned short icmp_cksum; /* ones complement cksum of struct */
|
||||
union {
|
||||
unsigned char ih_pptr; /* ICMP_PARAMPROB */
|
||||
struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
|
||||
struct ih_idseq {
|
||||
unsigned short icd_id;
|
||||
unsigned short icd_seq;
|
||||
} ih_idseq;
|
||||
int ih_void;
|
||||
|
||||
/* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
|
||||
struct ih_pmtu {
|
||||
unsigned short ipm_void;
|
||||
unsigned short ipm_nextmtu;
|
||||
} ih_pmtu;
|
||||
|
||||
struct ih_rtradv {
|
||||
unsigned char irt_num_addrs;
|
||||
unsigned char irt_wpa;
|
||||
unsigned short irt_lifetime;
|
||||
} ih_rtradv;
|
||||
} icmp_hun;
|
||||
#define icmp_pptr icmp_hun.ih_pptr
|
||||
#define icmp_gwaddr icmp_hun.ih_gwaddr
|
||||
#define icmp_id icmp_hun.ih_idseq.icd_id
|
||||
#define icmp_seq icmp_hun.ih_idseq.icd_seq
|
||||
#define icmp_void icmp_hun.ih_void
|
||||
#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
|
||||
#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
|
||||
union {
|
||||
struct id_ts {
|
||||
unsigned int its_otime;
|
||||
unsigned int its_rtime;
|
||||
unsigned int its_ttime;
|
||||
} id_ts;
|
||||
struct id_ip {
|
||||
struct ip idi_ip;
|
||||
/* options and then 64 bits of data */
|
||||
} id_ip;
|
||||
unsigned int id_mask;
|
||||
char id_data[1];
|
||||
} icmp_dun;
|
||||
#define icmp_otime icmp_dun.id_ts.its_otime
|
||||
#define icmp_rtime icmp_dun.id_ts.its_rtime
|
||||
#define icmp_ttime icmp_dun.id_ts.its_ttime
|
||||
#define icmp_ip icmp_dun.id_ip.idi_ip
|
||||
#define icmp_mask icmp_dun.id_mask
|
||||
#define icmp_data icmp_dun.id_data
|
||||
};
|
||||
|
||||
#define ICMP_ECHOREPLY 0 /* echo reply */
|
||||
#define ICMP_ECHO 8 /* echo service */
|
||||
|
||||
/*
|
||||
* ICMPv6 structures & constants
|
||||
*/
|
||||
|
||||
typedef struct icmp6_hdr {
|
||||
u_char icmp6_type; /* type field */
|
||||
u_char icmp6_code; /* code field */
|
||||
u_short icmp6_cksum; /* checksum field */
|
||||
union {
|
||||
u_int icmp6_un_data32[1]; /* type-specific field */
|
||||
u_short icmp6_un_data16[2]; /* type-specific field */
|
||||
u_char icmp6_un_data8[4]; /* type-specific field */
|
||||
} icmp6_dataun;
|
||||
} icmp6_t;
|
||||
|
||||
#define icmp6_data32 icmp6_dataun.icmp6_un_data32
|
||||
#define icmp6_data16 icmp6_dataun.icmp6_un_data16
|
||||
#define icmp6_data8 icmp6_dataun.icmp6_un_data8
|
||||
#define icmp6_pptr icmp6_data32[0] /* parameter prob */
|
||||
#define icmp6_mtu icmp6_data32[0] /* packet too big */
|
||||
#define icmp6_id icmp6_data16[0] /* echo request/reply */
|
||||
#define icmp6_seq icmp6_data16[1] /* echo request/reply */
|
||||
#define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */
|
||||
|
||||
struct ip6_pseudo_hdr /* for calculate the ICMPv6 checksum */
|
||||
{
|
||||
struct in6_addr ip6_src;
|
||||
struct in6_addr ip6_dst;
|
||||
u_int ip6_plen;
|
||||
u_int ip6_nxt;
|
||||
};
|
||||
|
||||
#define ICMP6_ECHO_REQUEST 128
|
||||
#define ICMP6_ECHO_REPLY 129
|
||||
#define IPPROTO_ICMPV6 58
|
||||
#define IPV6_UNICAST_HOPS 4 /* Set/get IP unicast hop limit */
|
||||
|
||||
|
||||
#endif
|
||||
@ -22,12 +22,10 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
#include "net_util.h"
|
||||
#include "jni.h"
|
||||
|
||||
#include "java_net_InetAddress.h"
|
||||
#include "java_net_SocketOptions.h"
|
||||
|
||||
// Taken from mstcpip.h in Windows SDK 8.0 or newer.
|
||||
#define SIO_LOOPBACK_FAST_PATH _WSAIOW(IOC_VENDOR,16)
|
||||
@ -593,7 +591,7 @@ NET_Timeout2(int fd, int fd1, long timeout, int *fdret) {
|
||||
|
||||
|
||||
void dumpAddr (char *str, void *addr) {
|
||||
struct SOCKADDR_IN6 *a = (struct SOCKADDR_IN6 *)addr;
|
||||
struct sockaddr_in6 *a = (struct sockaddr_in6 *)addr;
|
||||
int family = a->sin6_family;
|
||||
printf ("%s\n", str);
|
||||
if (family == AF_INET) {
|
||||
@ -812,7 +810,7 @@ NET_BindV6(struct ipv6bind *b, jboolean exclBind) {
|
||||
* 0 if error
|
||||
* > 0 interface index to use
|
||||
*/
|
||||
jint getDefaultIPv6Interface(JNIEnv *env, struct SOCKADDR_IN6 *target_addr)
|
||||
jint getDefaultIPv6Interface(JNIEnv *env, struct sockaddr_in6 *target_addr)
|
||||
{
|
||||
int ret;
|
||||
DWORD b;
|
||||
@ -866,9 +864,9 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
|
||||
int *len, jboolean v4MappedAddress) {
|
||||
jint family, iafam;
|
||||
iafam = getInetAddress_family(env, iaObj);
|
||||
family = (iafam == IPv4)? AF_INET : AF_INET6;
|
||||
family = (iafam == java_net_InetAddress_IPv4)? AF_INET : AF_INET6;
|
||||
if (ipv6_available() && !(family == AF_INET && v4MappedAddress == JNI_FALSE)) {
|
||||
struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him;
|
||||
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
|
||||
jbyte caddr[16];
|
||||
jint address, scopeid = 0;
|
||||
jint cached_scope_id = 0;
|
||||
@ -894,7 +892,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
|
||||
cached_scope_id = (jint)(*env)->GetIntField(env, iaObj, ia6_cachedscopeidID);
|
||||
}
|
||||
|
||||
memset((char *)him6, 0, sizeof(struct SOCKADDR_IN6));
|
||||
memset((char *)him6, 0, sizeof(struct sockaddr_in6));
|
||||
him6->sin6_port = (u_short) htons((u_short)port);
|
||||
memcpy((void *)&(him6->sin6_addr), caddr, sizeof(struct in6_addr) );
|
||||
him6->sin6_family = AF_INET6;
|
||||
@ -904,7 +902,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr
|
||||
(*env)->SetIntField(env, iaObj, ia6_cachedscopeidID, cached_scope_id);
|
||||
}
|
||||
him6->sin6_scope_id = scopeid != 0 ? scopeid : cached_scope_id;
|
||||
*len = sizeof(struct SOCKADDR_IN6) ;
|
||||
*len = sizeof(struct sockaddr_in6) ;
|
||||
} else {
|
||||
struct sockaddr_in *him4 = (struct sockaddr_in *)him;
|
||||
jint address;
|
||||
@ -964,12 +962,12 @@ NET_IsEqual(jbyte* caddr1, jbyte* caddr2) {
|
||||
}
|
||||
|
||||
int getScopeID(struct sockaddr *him) {
|
||||
struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him;
|
||||
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
|
||||
return him6->sin6_scope_id;
|
||||
}
|
||||
|
||||
int cmpScopeID(unsigned int scope, struct sockaddr *him) {
|
||||
struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him;
|
||||
struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him;
|
||||
return him6->sin6_scope_id == scope;
|
||||
}
|
||||
|
||||
|
||||
@ -22,195 +22,10 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
|
||||
/* typedefs that were defined correctly for the first time
|
||||
* in Nov. 2001 SDK, which we need to include here.
|
||||
* Specifically, in6_addr and sockaddr_in6 (which is defined but
|
||||
* not correctly). When moving to a later SDK remove following
|
||||
* code between START and END
|
||||
*/
|
||||
|
||||
/* --- START --- */
|
||||
|
||||
/* WIN64 already uses newer SDK */
|
||||
#ifdef _WIN64
|
||||
|
||||
#define SOCKADDR_IN6 sockaddr_in6
|
||||
|
||||
#else
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define WS2TCPIP_INLINE __inline
|
||||
#else
|
||||
#define WS2TCPIP_INLINE extern inline /* GNU style */
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1310
|
||||
|
||||
#define SOCKADDR_IN6 sockaddr_in6
|
||||
|
||||
#else
|
||||
|
||||
/*SO_REUSEPORT is not supported on Windows, define it to 0*/
|
||||
#define SO_REUSEPORT 0
|
||||
|
||||
/* Retain this code a little longer to support building in
|
||||
* old environments. _MSC_VER is defined as:
|
||||
* 1200 for MSVC++ 6.0
|
||||
* 1310 for Vc7
|
||||
*/
|
||||
|
||||
#define IPPROTO_IPV6 41
|
||||
#define IPV6_MULTICAST_IF 9
|
||||
|
||||
struct in6_addr {
|
||||
union {
|
||||
u_char Byte[16];
|
||||
u_short Word[8];
|
||||
} u;
|
||||
};
|
||||
|
||||
/*
|
||||
** Defines to match RFC 2553.
|
||||
*/
|
||||
#define _S6_un u
|
||||
#define _S6_u8 Byte
|
||||
#define s6_addr _S6_un._S6_u8
|
||||
|
||||
/*
|
||||
** Defines for our implementation.
|
||||
*/
|
||||
#define s6_bytes u.Byte
|
||||
#define s6_words u.Word
|
||||
|
||||
/* IPv6 socket address structure, RFC 2553 */
|
||||
|
||||
struct SOCKADDR_IN6 {
|
||||
short sin6_family; /* AF_INET6 */
|
||||
u_short sin6_port; /* Transport level port number */
|
||||
u_long sin6_flowinfo; /* IPv6 flow information */
|
||||
struct in6_addr sin6_addr; /* IPv6 address */
|
||||
u_long sin6_scope_id; /* set of interfaces for a scope */
|
||||
};
|
||||
|
||||
|
||||
/* Error codes from getaddrinfo() */
|
||||
|
||||
#define EAI_AGAIN WSATRY_AGAIN
|
||||
#define EAI_BADFLAGS WSAEINVAL
|
||||
#define EAI_FAIL WSANO_RECOVERY
|
||||
#define EAI_FAMILY WSAEAFNOSUPPORT
|
||||
#define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
|
||||
//#define EAI_NODATA WSANO_DATA
|
||||
#define EAI_NONAME WSAHOST_NOT_FOUND
|
||||
#define EAI_SERVICE WSATYPE_NOT_FOUND
|
||||
#define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
|
||||
|
||||
#define EAI_NODATA EAI_NONAME
|
||||
|
||||
/* Structure used in getaddrinfo() call */
|
||||
|
||||
typedef struct addrinfo {
|
||||
int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
|
||||
int ai_family; /* PF_xxx */
|
||||
int ai_socktype; /* SOCK_xxx */
|
||||
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
|
||||
size_t ai_addrlen; /* Length of ai_addr */
|
||||
char *ai_canonname; /* Canonical name for nodename */
|
||||
struct sockaddr *ai_addr; /* Binary address */
|
||||
struct addrinfo *ai_next; /* Next structure in linked list */
|
||||
} ADDRINFO, FAR * LPADDRINFO;
|
||||
|
||||
/* Flags used in "hints" argument to getaddrinfo() */
|
||||
|
||||
#define AI_PASSIVE 0x1 /* Socket address will be used in bind() call */
|
||||
#define AI_CANONNAME 0x2 /* Return canonical name in first ai_canonname */
|
||||
#define AI_NUMERICHOST 0x4 /* Nodename must be a numeric address string */
|
||||
|
||||
/* IPv6 Multicasting definitions */
|
||||
|
||||
/* Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP */
|
||||
|
||||
typedef struct ipv6_mreq {
|
||||
struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast address */
|
||||
unsigned int ipv6mr_interface; /* Interface index */
|
||||
} IPV6_MREQ;
|
||||
|
||||
#define IPV6_ADD_MEMBERSHIP 12 /* Add an IP group membership */
|
||||
#define IPV6_DROP_MEMBERSHIP 13 /* Drop an IP group membership */
|
||||
#define IPV6_MULTICAST_LOOP 11 /* Set/get IP multicast loopback */
|
||||
|
||||
WS2TCPIP_INLINE int
|
||||
IN6_IS_ADDR_MULTICAST(const struct in6_addr *a)
|
||||
{
|
||||
return (a->s6_bytes[0] == 0xff);
|
||||
}
|
||||
|
||||
WS2TCPIP_INLINE int
|
||||
IN6_IS_ADDR_LINKLOCAL(const struct in6_addr *a)
|
||||
{
|
||||
return (a->s6_bytes[0] == 0xfe
|
||||
&& a->s6_bytes[1] == 0x80);
|
||||
}
|
||||
|
||||
#define NI_MAXHOST 1025 /* Max size of a fully-qualified domain name */
|
||||
#define NI_MAXSERV 32 /* Max size of a service name */
|
||||
|
||||
#define INET_ADDRSTRLEN 16 /* Max size of numeric form of IPv4 address */
|
||||
#define INET6_ADDRSTRLEN 46 /* Max size of numeric form of IPv6 address */
|
||||
|
||||
/* Flags for getnameinfo() */
|
||||
|
||||
#define NI_NOFQDN 0x01 /* Only return nodename portion for local hosts */
|
||||
#define NI_NUMERICHOST 0x02 /* Return numeric form of the host's address */
|
||||
#define NI_NAMEREQD 0x04 /* Error if the host's name not in DNS */
|
||||
#define NI_NUMERICSERV 0x08 /* Return numeric form of the service (port #) */
|
||||
#define NI_DGRAM 0x10 /* Service is a datagram service */
|
||||
|
||||
|
||||
#define IN6_IS_ADDR_V4MAPPED(a) \
|
||||
(((a)->s6_words[0] == 0) && ((a)->s6_words[1] == 0) && \
|
||||
((a)->s6_words[2] == 0) && ((a)->s6_words[3] == 0) && \
|
||||
((a)->s6_words[4] == 0) && ((a)->s6_words[5] == 0xffff))
|
||||
|
||||
|
||||
/* --- END --- */
|
||||
#endif /* end 'else older build environment' */
|
||||
|
||||
#endif
|
||||
|
||||
#if !INCL_WINSOCK_API_TYPEDEFS
|
||||
|
||||
typedef
|
||||
int
|
||||
(WSAAPI * LPFN_GETADDRINFO)(
|
||||
IN const char FAR * nodename,
|
||||
IN const char FAR * servname,
|
||||
IN const struct addrinfo FAR * hints,
|
||||
OUT struct addrinfo FAR * FAR * res
|
||||
);
|
||||
|
||||
typedef
|
||||
void
|
||||
(WSAAPI * LPFN_FREEADDRINFO)(
|
||||
IN struct addrinfo FAR * ai
|
||||
);
|
||||
|
||||
typedef
|
||||
int
|
||||
(WSAAPI * LPFN_GETNAMEINFO)(
|
||||
IN const struct sockaddr FAR * sa,
|
||||
IN int salen,
|
||||
OUT char FAR * host,
|
||||
IN DWORD hostlen,
|
||||
OUT char FAR * serv,
|
||||
IN DWORD servlen,
|
||||
IN int flags
|
||||
);
|
||||
#endif
|
||||
#include <iphlpapi.h>
|
||||
#include <icmpapi.h>
|
||||
|
||||
/* used to disable connection reset messages on Windows XP */
|
||||
#ifndef SIO_UDP_CONNRESET
|
||||
@ -229,13 +44,9 @@ int
|
||||
#define IPV6_V6ONLY 27 /* Treat wildcard bind as AF_INET6-only. */
|
||||
#endif
|
||||
|
||||
#include "java_io_FileDescriptor.h"
|
||||
#include "java_net_SocketOptions.h"
|
||||
|
||||
#define MAX_BUFFER_LEN 2048
|
||||
#define MAX_HEAP_BUFFER_LEN 65536
|
||||
|
||||
|
||||
/* true if SO_RCVTIMEO is supported by underlying provider */
|
||||
extern jboolean isRcvTimeoutSupported;
|
||||
|
||||
@ -249,7 +60,7 @@ int NET_GetDefaultTOS(void);
|
||||
typedef union {
|
||||
struct sockaddr sa;
|
||||
struct sockaddr_in sa4;
|
||||
struct SOCKADDR_IN6 sa6;
|
||||
struct sockaddr_in6 sa6;
|
||||
} SOCKETADDRESS;
|
||||
|
||||
/*
|
||||
@ -264,7 +75,7 @@ struct ipv6bind {
|
||||
|
||||
#define SOCKETADDRESS_COPY(DST,SRC) { \
|
||||
if ((SRC)->sa_family == AF_INET6) { \
|
||||
memcpy ((DST), (SRC), sizeof (struct SOCKADDR_IN6)); \
|
||||
memcpy ((DST), (SRC), sizeof (struct sockaddr_in6)); \
|
||||
} else { \
|
||||
memcpy ((DST), (SRC), sizeof (struct sockaddr_in)); \
|
||||
} \
|
||||
|
||||
@ -202,6 +202,7 @@ Java_sun_nio_ch_FileDispatcherImpl_write0(JNIEnv *env, jclass clazz, jobject fdo
|
||||
|
||||
if ((h == INVALID_HANDLE_VALUE) || (result == 0)) {
|
||||
JNU_ThrowIOExceptionWithLastError(env, "Write failed");
|
||||
return IOS_THROWN;
|
||||
}
|
||||
|
||||
return convertReturnVal(env, (jint)written, JNI_FALSE);
|
||||
@ -250,6 +251,7 @@ Java_sun_nio_ch_FileDispatcherImpl_writev0(JNIEnv *env, jclass clazz, jobject fd
|
||||
|
||||
if ((h == INVALID_HANDLE_VALUE) || (result == 0)) {
|
||||
JNU_ThrowIOExceptionWithLastError(env, "Write failed");
|
||||
return IOS_THROWN;
|
||||
}
|
||||
|
||||
return convertLongReturnVal(env, totalWritten, JNI_FALSE);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1995, 2016, 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
|
||||
@ -40,36 +40,25 @@ import java.util.HashSet;
|
||||
import java.util.StringTokenizer;
|
||||
import java.security.*;
|
||||
import java.lang.reflect.*;
|
||||
import jdk.internal.misc.JavaNetURLClassLoaderAccess;
|
||||
import jdk.internal.misc.JavaSecurityAccess;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
import sun.awt.AWTSecurityManager;
|
||||
import sun.awt.AppContext;
|
||||
import sun.awt.AWTPermissions;
|
||||
import sun.security.util.SecurityConstants;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This class defines an applet security policy
|
||||
*
|
||||
*/
|
||||
public
|
||||
class AppletSecurity extends AWTSecurityManager {
|
||||
|
||||
//URLClassLoader.acc
|
||||
private static Field facc = null;
|
||||
|
||||
//AccessControlContext.context;
|
||||
private static Field fcontext = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
facc = URLClassLoader.class.getDeclaredField("acc");
|
||||
facc.setAccessible(true);
|
||||
fcontext = AccessControlContext.class.getDeclaredField("context");
|
||||
fcontext.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new UnsupportedOperationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static final JavaNetURLClassLoaderAccess JNUCLA
|
||||
= SharedSecrets.getJavaNetURLClassLoaderAccess();
|
||||
private static final JavaSecurityAccess JSA = SharedSecrets.getJavaSecurityAccess();
|
||||
|
||||
/**
|
||||
* Construct and initialize.
|
||||
@ -148,6 +137,7 @@ class AppletSecurity extends AWTSecurityManager {
|
||||
final ClassLoader currentLoader = context[i].getClassLoader();
|
||||
|
||||
if (currentLoader instanceof URLClassLoader) {
|
||||
URLClassLoader ld = (URLClassLoader)currentLoader;
|
||||
loader = AccessController.doPrivileged(
|
||||
new PrivilegedAction<ClassLoader>() {
|
||||
public ClassLoader run() {
|
||||
@ -156,12 +146,12 @@ class AppletSecurity extends AWTSecurityManager {
|
||||
ProtectionDomain[] pds = null;
|
||||
|
||||
try {
|
||||
acc = (AccessControlContext) facc.get(currentLoader);
|
||||
acc = JNUCLA.getAccessControlContext(ld);
|
||||
if (acc == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
pds = (ProtectionDomain[]) fcontext.get(acc);
|
||||
pds = JSA.getProtectDomains(acc);
|
||||
if (pds == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -1970,6 +1970,11 @@ public class Activation implements Serializable {
|
||||
AccessController.doPrivileged(
|
||||
new PrivilegedExceptionAction<Void>() {
|
||||
public Void run() throws IOException {
|
||||
boolean disable = Boolean.getBoolean(
|
||||
"sun.rmi.server.activation.disableErrRedirect");
|
||||
if (disable)
|
||||
return null;
|
||||
|
||||
File file =
|
||||
Files.createTempFile("rmid-err", null).toFile();
|
||||
PrintStream errStream =
|
||||
|
||||
@ -36,6 +36,7 @@
|
||||
#include <BaseTsd.h>
|
||||
#include <wincrypt.h>
|
||||
#include <stdio.h>
|
||||
#include <memory>
|
||||
|
||||
|
||||
#define OID_EKU_ANY "2.5.29.37.0"
|
||||
@ -48,6 +49,7 @@
|
||||
#define KEYSTORE_EXCEPTION "java/security/KeyStoreException"
|
||||
#define PROVIDER_EXCEPTION "java/security/ProviderException"
|
||||
#define SIGNATURE_EXCEPTION "java/security/SignatureException"
|
||||
#define OUT_OF_MEMORY_ERROR "java/lang/OutOfMemoryError"
|
||||
|
||||
extern "C" {
|
||||
|
||||
@ -56,11 +58,23 @@ extern "C" {
|
||||
*/
|
||||
DEF_STATIC_JNI_OnLoad
|
||||
|
||||
/*
|
||||
* Throws an arbitrary Java exception with the given message.
|
||||
*/
|
||||
void ThrowExceptionWithMessage(JNIEnv *env, const char *exceptionName,
|
||||
const char *szMessage)
|
||||
{
|
||||
jclass exceptionClazz = env->FindClass(exceptionName);
|
||||
if (exceptionClazz != NULL) {
|
||||
env->ThrowNew(exceptionClazz, szMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Throws an arbitrary Java exception.
|
||||
* The exception message is a Windows system error message.
|
||||
*/
|
||||
void ThrowException(JNIEnv *env, char *exceptionName, DWORD dwError)
|
||||
void ThrowException(JNIEnv *env, const char *exceptionName, DWORD dwError)
|
||||
{
|
||||
char szMessage[1024];
|
||||
szMessage[0] = '\0';
|
||||
@ -71,12 +85,22 @@ void ThrowException(JNIEnv *env, char *exceptionName, DWORD dwError)
|
||||
strcpy(szMessage, "Unknown error");
|
||||
}
|
||||
|
||||
jclass exceptionClazz = env->FindClass(exceptionName);
|
||||
if (exceptionClazz != NULL) {
|
||||
env->ThrowNew(exceptionClazz, szMessage);
|
||||
}
|
||||
ThrowExceptionWithMessage(env, exceptionName, szMessage);
|
||||
}
|
||||
|
||||
/*
|
||||
* Overloaded 'operator new[]' variant, which will raise Java's
|
||||
* OutOfMemoryError in the case of a failure.
|
||||
*/
|
||||
static void* operator new[](std::size_t size, JNIEnv *env)
|
||||
{
|
||||
void* buf = ::operator new[](size, std::nothrow);
|
||||
if (buf == NULL) {
|
||||
ThrowExceptionWithMessage(env, OUT_OF_MEMORY_ERROR,
|
||||
"Native memory allocation failed");
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* Maps the name of a hash algorithm to an algorithm identifier.
|
||||
@ -211,7 +235,10 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_PRNG_generateSeed
|
||||
|
||||
} else if (length > 0) {
|
||||
|
||||
pbData = new BYTE[length];
|
||||
pbData = new (env) BYTE[length];
|
||||
if (pbData == NULL) {
|
||||
__leave;
|
||||
}
|
||||
|
||||
if (::CryptGenRandom(
|
||||
hCryptProv,
|
||||
@ -441,7 +468,11 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_loadKeysOrCertificateCh
|
||||
NULL, 0)) > 1) {
|
||||
|
||||
// Found friendly name
|
||||
pszNameString = new char[cchNameString];
|
||||
pszNameString = new (env) char[cchNameString];
|
||||
if (pszNameString == NULL) {
|
||||
__leave;
|
||||
}
|
||||
|
||||
CertGetNameString(pc,
|
||||
CERT_NAME_FRIENDLY_DISPLAY_TYPE, 0, NULL,
|
||||
pszNameString, cchNameString);
|
||||
@ -578,7 +609,10 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSASignature_signHash
|
||||
}
|
||||
|
||||
// Copy hash from Java to native buffer
|
||||
pHashBuffer = new jbyte[jHashSize];
|
||||
pHashBuffer = new (env) jbyte[jHashSize];
|
||||
if (pHashBuffer == NULL) {
|
||||
__leave;
|
||||
}
|
||||
env->GetByteArrayRegion(jHash, 0, jHashSize, pHashBuffer);
|
||||
|
||||
// Set hash value in the hash object
|
||||
@ -616,7 +650,10 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSASignature_signHash
|
||||
__leave;
|
||||
}
|
||||
|
||||
pSignedHashBuffer = new jbyte[dwBufLen];
|
||||
pSignedHashBuffer = new (env) jbyte[dwBufLen];
|
||||
if (pSignedHashBuffer == NULL) {
|
||||
__leave;
|
||||
}
|
||||
if (::CryptSignHash(hHash, dwKeySpec, NULL, dwFlags, (BYTE*)pSignedHashBuffer, &dwBufLen) == FALSE)
|
||||
{
|
||||
ThrowException(env, SIGNATURE_EXCEPTION, GetLastError());
|
||||
@ -704,9 +741,16 @@ JNIEXPORT jboolean JNICALL Java_sun_security_mscapi_RSASignature_verifySignedHas
|
||||
}
|
||||
|
||||
// Copy hash and signedHash from Java to native buffer
|
||||
pHashBuffer = new jbyte[jHashSize];
|
||||
pHashBuffer = new (env) jbyte[jHashSize];
|
||||
if (pHashBuffer == NULL) {
|
||||
__leave;
|
||||
}
|
||||
env->GetByteArrayRegion(jHash, 0, jHashSize, pHashBuffer);
|
||||
pSignedHashBuffer = new jbyte[jSignedHashSize];
|
||||
|
||||
pSignedHashBuffer = new (env) jbyte[jSignedHashSize];
|
||||
if (pSignedHashBuffer == NULL) {
|
||||
__leave;
|
||||
}
|
||||
env->GetByteArrayRegion(jSignedHash, 0, jSignedHashSize,
|
||||
pSignedHashBuffer);
|
||||
|
||||
@ -919,7 +963,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_storeCertificate
|
||||
}
|
||||
|
||||
// Copy encoding from Java to native buffer
|
||||
pbCertEncoding = new jbyte[jCertEncodingSize];
|
||||
pbCertEncoding = new (env) jbyte[jCertEncodingSize];
|
||||
if (pbCertEncoding == NULL) {
|
||||
__leave;
|
||||
}
|
||||
env->GetByteArrayRegion(jCertEncoding, 0, jCertEncodingSize, pbCertEncoding);
|
||||
|
||||
// Create a certificate context from the encoded cert
|
||||
@ -932,7 +979,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_storeCertificate
|
||||
|
||||
// Set the certificate's friendly name
|
||||
int size = env->GetStringLength(jCertAliasName);
|
||||
pszCertAliasName = new WCHAR[size + 1];
|
||||
pszCertAliasName = new (env) WCHAR[size + 1];
|
||||
if (pszCertAliasName == NULL) {
|
||||
__leave;
|
||||
}
|
||||
|
||||
jCertAliasChars = env->GetStringChars(jCertAliasName, NULL);
|
||||
memcpy(pszCertAliasName, jCertAliasChars, size * sizeof(WCHAR));
|
||||
@ -970,7 +1020,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_storeCertificate
|
||||
__leave;
|
||||
}
|
||||
|
||||
pszContainerName = new char[dwDataLen];
|
||||
pszContainerName = new (env) char[dwDataLen];
|
||||
if (pszContainerName == NULL) {
|
||||
__leave;
|
||||
}
|
||||
|
||||
if (! ::CryptGetProvParam(
|
||||
(HCRYPTPROV) hCryptProv,
|
||||
@ -984,7 +1037,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_storeCertificate
|
||||
}
|
||||
|
||||
// Convert to a wide char string
|
||||
pwszContainerName = new WCHAR[dwDataLen];
|
||||
pwszContainerName = new (env) WCHAR[dwDataLen];
|
||||
if (pwszContainerName == NULL) {
|
||||
__leave;
|
||||
}
|
||||
|
||||
if (mbstowcs(pwszContainerName, pszContainerName, dwDataLen) == 0) {
|
||||
ThrowException(env, KEYSTORE_EXCEPTION, GetLastError());
|
||||
@ -1007,7 +1063,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_storeCertificate
|
||||
__leave;
|
||||
}
|
||||
|
||||
pszProviderName = new char[dwDataLen];
|
||||
pszProviderName = new (env) char[dwDataLen];
|
||||
if (pszProviderName == NULL) {
|
||||
__leave;
|
||||
}
|
||||
|
||||
if (! ::CryptGetProvParam(
|
||||
(HCRYPTPROV) hCryptProv,
|
||||
@ -1021,7 +1080,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_storeCertificate
|
||||
}
|
||||
|
||||
// Convert to a wide char string
|
||||
pwszProviderName = new WCHAR[dwDataLen];
|
||||
pwszProviderName = new (env) WCHAR[dwDataLen];
|
||||
if (pwszProviderName == NULL) {
|
||||
__leave;
|
||||
}
|
||||
|
||||
if (mbstowcs(pwszProviderName, pszProviderName, dwDataLen) == 0) {
|
||||
ThrowException(env, KEYSTORE_EXCEPTION, GetLastError());
|
||||
@ -1161,7 +1223,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_removeCertificate
|
||||
}
|
||||
|
||||
// Copy encoding from Java to native buffer
|
||||
pbCertEncoding = new jbyte[jCertEncodingSize];
|
||||
pbCertEncoding = new (env) jbyte[jCertEncodingSize];
|
||||
if (pbCertEncoding == NULL) {
|
||||
__leave;
|
||||
}
|
||||
env->GetByteArrayRegion(jCertEncoding, 0, jCertEncodingSize, pbCertEncoding);
|
||||
|
||||
// Create a certificate context from the encoded cert
|
||||
@ -1184,7 +1249,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_removeCertificate
|
||||
if ((cchNameString = ::CertGetNameString(pTBDCertContext,
|
||||
CERT_NAME_FRIENDLY_DISPLAY_TYPE, 0, NULL, NULL, 0)) > 1) {
|
||||
|
||||
pszNameString = new char[cchNameString];
|
||||
pszNameString = new (env) char[cchNameString];
|
||||
if (pszNameString == NULL) {
|
||||
__leave;
|
||||
}
|
||||
|
||||
::CertGetNameString(pTBDCertContext,
|
||||
CERT_NAME_FRIENDLY_DISPLAY_TYPE, 0, NULL, pszNameString,
|
||||
@ -1334,7 +1402,10 @@ JNIEXPORT jlong JNICALL Java_sun_security_mscapi_RSACipher_findCertificateUsingA
|
||||
continue; // not found
|
||||
}
|
||||
|
||||
pszNameString = new char[cchNameString];
|
||||
pszNameString = new (env) char[cchNameString];
|
||||
if (pszNameString == NULL) {
|
||||
__leave;
|
||||
}
|
||||
|
||||
if (::CertGetNameString(pCertContext,
|
||||
CERT_NAME_FRIENDLY_DISPLAY_TYPE, 0, NULL, pszNameString,
|
||||
@ -1510,7 +1581,10 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSACipher_encryptDecrypt
|
||||
__try
|
||||
{
|
||||
// Copy data from Java buffer to native buffer
|
||||
pData = new jbyte[dwBufLen];
|
||||
pData = new (env) jbyte[dwBufLen];
|
||||
if (pData == NULL) {
|
||||
__leave;
|
||||
}
|
||||
env->GetByteArrayRegion(jData, 0, dwBufLen, pData);
|
||||
|
||||
if (doEncrypt == JNI_TRUE) {
|
||||
@ -1584,7 +1658,10 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSAPublicKey_getPublicKeyB
|
||||
__leave;
|
||||
}
|
||||
|
||||
pbKeyBlob = new BYTE[dwBlobLen];
|
||||
pbKeyBlob = new (env) BYTE[dwBlobLen];
|
||||
if (pbKeyBlob == NULL) {
|
||||
__leave;
|
||||
}
|
||||
|
||||
// Generate key blob
|
||||
if (! ::CryptExportKey((HCRYPTKEY) hCryptKey, 0, PUBLICKEYBLOB, 0,
|
||||
@ -1638,8 +1715,12 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSAPublicKey_getExponent
|
||||
|
||||
RSAPUBKEY* pRsaPubKey =
|
||||
(RSAPUBKEY *) (keyBlob + sizeof(PUBLICKEYSTRUC));
|
||||
|
||||
int len = sizeof(pRsaPubKey->pubexp);
|
||||
exponentBytes = new jbyte[len];
|
||||
exponentBytes = new (env) jbyte[len];
|
||||
if (exponentBytes == NULL) {
|
||||
__leave;
|
||||
}
|
||||
|
||||
// convert from little-endian while copying from blob
|
||||
for (int i = 0, j = len - 1; i < len; i++, j--) {
|
||||
@ -1690,9 +1771,12 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSAPublicKey_getModulus
|
||||
|
||||
RSAPUBKEY* pRsaPubKey =
|
||||
(RSAPUBKEY *) (keyBlob + sizeof(PUBLICKEYSTRUC));
|
||||
int len = pRsaPubKey->bitlen / 8;
|
||||
|
||||
modulusBytes = new jbyte[len];
|
||||
int len = pRsaPubKey->bitlen / 8;
|
||||
modulusBytes = new (env) jbyte[len];
|
||||
if (modulusBytes == NULL) {
|
||||
__leave;
|
||||
}
|
||||
BYTE * pbModulus =
|
||||
(BYTE *) (keyBlob + sizeof(PUBLICKEYSTRUC) + sizeof(RSAPUBKEY));
|
||||
|
||||
@ -1813,12 +1897,16 @@ jbyteArray generateKeyBlob(
|
||||
(jKeyBitLength / 8);
|
||||
}
|
||||
|
||||
jbyte* jBlobBytes = new jbyte[jBlobLength];
|
||||
jbyte* jBlobBytes = NULL;
|
||||
jbyte* jBlobElement;
|
||||
jbyteArray jBlob = NULL;
|
||||
jsize jElementLength;
|
||||
|
||||
__try {
|
||||
jBlobBytes = new (env) jbyte[jBlobLength];
|
||||
if (jBlobBytes == NULL) {
|
||||
__leave;
|
||||
}
|
||||
|
||||
BLOBHEADER *pBlobHeader = (BLOBHEADER *) jBlobBytes;
|
||||
if (bGeneratePrivateKeyBlob) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2016, 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
|
||||
@ -32,7 +32,6 @@ import java.util.*;
|
||||
|
||||
import java.security.*;
|
||||
|
||||
import sun.security.action.GetPropertyAction;
|
||||
import sun.security.util.PropertyExpander;
|
||||
|
||||
import sun.security.pkcs11.wrapper.*;
|
||||
@ -58,15 +57,30 @@ final class Config {
|
||||
// will accept single threaded modules regardless of the setting in their
|
||||
// config files.
|
||||
private static final boolean staticAllowSingleThreadedModules;
|
||||
private static final String osName;
|
||||
private static final String osArch;
|
||||
|
||||
static {
|
||||
String p = "sun.security.pkcs11.allowSingleThreadedModules";
|
||||
String s = AccessController.doPrivileged(new GetPropertyAction(p));
|
||||
if ("false".equalsIgnoreCase(s)) {
|
||||
List<String> props = AccessController.doPrivileged(
|
||||
new PrivilegedAction<>() {
|
||||
@Override
|
||||
public List<String> run() {
|
||||
return List.of(
|
||||
System.getProperty(
|
||||
"sun.security.pkcs11.allowSingleThreadedModules",
|
||||
"true"),
|
||||
System.getProperty("os.name"),
|
||||
System.getProperty("os.arch"));
|
||||
}
|
||||
}
|
||||
);
|
||||
if ("false".equalsIgnoreCase(props.get(0))) {
|
||||
staticAllowSingleThreadedModules = false;
|
||||
} else {
|
||||
staticAllowSingleThreadedModules = true;
|
||||
}
|
||||
osName = props.get(1);
|
||||
osArch = props.get(2);
|
||||
}
|
||||
|
||||
private final static boolean DEBUG = false;
|
||||
@ -650,8 +664,6 @@ final class Config {
|
||||
// replace "/$ISA/" with "/sparcv9/" on 64-bit Solaris SPARC
|
||||
// and with "/amd64/" on Solaris AMD64.
|
||||
// On all other platforms, just turn it into a "/"
|
||||
String osName = System.getProperty("os.name", "");
|
||||
String osArch = System.getProperty("os.arch", "");
|
||||
String prefix = lib.substring(0, i);
|
||||
String suffix = lib.substring(i + 5);
|
||||
if (osName.equals("SunOS") && osArch.equals("sparcv9")) {
|
||||
|
||||
@ -58,7 +58,7 @@ package sun.security.pkcs11.wrapper;
|
||||
*/
|
||||
public class Constants {
|
||||
|
||||
public static final String NEWLINE = System.getProperty("line.separator");
|
||||
public static final String NEWLINE = System.lineSeparator();
|
||||
|
||||
public static final String INDENT = " ";
|
||||
|
||||
|
||||
@ -24,7 +24,6 @@
|
||||
*/
|
||||
|
||||
module jdk.httpserver {
|
||||
requires java.logging;
|
||||
|
||||
exports com.sun.net.httpserver;
|
||||
exports com.sun.net.httpserver.spi;
|
||||
|
||||
@ -29,7 +29,8 @@ import java.io.*;
|
||||
import java.net.*;
|
||||
import javax.net.ssl.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.text.*;
|
||||
import com.sun.net.httpserver.*;
|
||||
|
||||
@ -221,7 +222,7 @@ class ExchangeImpl {
|
||||
Logger logger = server.getLogger();
|
||||
String msg = "sendResponseHeaders: rCode = "+ rCode
|
||||
+ ": forcing contentLen = -1";
|
||||
logger.warning (msg);
|
||||
logger.log (Level.WARNING, msg);
|
||||
}
|
||||
contentLen = -1;
|
||||
}
|
||||
@ -234,7 +235,7 @@ class ExchangeImpl {
|
||||
final Logger logger = server.getLogger();
|
||||
String msg =
|
||||
"sendResponseHeaders: being invoked with a content length for a HEAD request";
|
||||
logger.warning (msg);
|
||||
logger.log (Level.WARNING, msg);
|
||||
}
|
||||
noContentToSend = true;
|
||||
contentLen = 0;
|
||||
|
||||
@ -28,7 +28,8 @@ package sun.net.httpserver;
|
||||
import java.io.*;
|
||||
import javax.net.ssl.*;
|
||||
import java.nio.channels.*;
|
||||
import java.util.logging.Logger;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import com.sun.net.httpserver.*;
|
||||
import com.sun.net.httpserver.spi.*;
|
||||
|
||||
@ -119,7 +120,7 @@ class HttpConnection {
|
||||
}
|
||||
closed = true;
|
||||
if (logger != null && chan != null) {
|
||||
logger.finest ("Closing connection: " + chan.toString());
|
||||
logger.log (Level.TRACE, "Closing connection: " + chan.toString());
|
||||
}
|
||||
|
||||
if (!chan.isOpen()) {
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
package sun.net.httpserver;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
import java.lang.System.Logger;
|
||||
import com.sun.net.httpserver.*;
|
||||
import com.sun.net.httpserver.spi.*;
|
||||
|
||||
|
||||
@ -25,7 +25,8 @@
|
||||
|
||||
package sun.net.httpserver;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
/**
|
||||
@ -115,7 +116,8 @@ class ServerConfig {
|
||||
if (System.getProperty("sun.net.httpserver.readTimeout")
|
||||
!=null)
|
||||
{
|
||||
logger.warning ("sun.net.httpserver.readTimeout "+
|
||||
logger.log (Level.WARNING,
|
||||
"sun.net.httpserver.readTimeout "+
|
||||
"property is no longer used. "+
|
||||
"Use sun.net.httpserver.maxReqTime instead."
|
||||
);
|
||||
@ -123,7 +125,8 @@ class ServerConfig {
|
||||
if (System.getProperty("sun.net.httpserver.writeTimeout")
|
||||
!=null)
|
||||
{
|
||||
logger.warning ("sun.net.httpserver.writeTimeout "+
|
||||
logger.log (Level.WARNING,
|
||||
"sun.net.httpserver.writeTimeout "+
|
||||
"property is no longer used. Use "+
|
||||
"sun.net.httpserver.maxRspTime instead."
|
||||
);
|
||||
@ -131,7 +134,8 @@ class ServerConfig {
|
||||
if (System.getProperty("sun.net.httpserver.selCacheTimeout")
|
||||
!=null)
|
||||
{
|
||||
logger.warning ("sun.net.httpserver.selCacheTimeout "+
|
||||
logger.log (Level.WARNING,
|
||||
"sun.net.httpserver.selCacheTimeout "+
|
||||
"property is no longer used."
|
||||
);
|
||||
}
|
||||
|
||||
@ -30,8 +30,8 @@ import java.io.*;
|
||||
import java.nio.channels.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import javax.net.ssl.*;
|
||||
import com.sun.net.httpserver.*;
|
||||
import java.security.AccessController;
|
||||
@ -81,7 +81,7 @@ class ServerImpl implements TimeSource {
|
||||
final static boolean timer1Enabled = MAX_REQ_TIME != -1 || MAX_RSP_TIME != -1;
|
||||
|
||||
private Timer timer, timer1;
|
||||
private Logger logger;
|
||||
private final Logger logger;
|
||||
private Thread dispatcherThread;
|
||||
|
||||
ServerImpl (
|
||||
@ -90,7 +90,7 @@ class ServerImpl implements TimeSource {
|
||||
|
||||
this.protocol = protocol;
|
||||
this.wrapper = wrapper;
|
||||
this.logger = Logger.getLogger ("com.sun.net.httpserver");
|
||||
this.logger = System.getLogger ("com.sun.net.httpserver");
|
||||
ServerConfig.checkLegacyProperties (logger);
|
||||
https = protocol.equalsIgnoreCase ("https");
|
||||
this.address = addr;
|
||||
@ -115,12 +115,12 @@ class ServerImpl implements TimeSource {
|
||||
if (timer1Enabled) {
|
||||
timer1 = new Timer ("server-timer1", true);
|
||||
timer1.schedule (new ServerTimerTask1(),TIMER_MILLIS,TIMER_MILLIS);
|
||||
logger.config ("HttpServer timer1 enabled period in ms: "+TIMER_MILLIS);
|
||||
logger.config ("MAX_REQ_TIME: "+MAX_REQ_TIME);
|
||||
logger.config ("MAX_RSP_TIME: "+MAX_RSP_TIME);
|
||||
logger.log (Level.DEBUG, "HttpServer timer1 enabled period in ms: ", TIMER_MILLIS);
|
||||
logger.log (Level.DEBUG, "MAX_REQ_TIME: "+MAX_REQ_TIME);
|
||||
logger.log (Level.DEBUG, "MAX_RSP_TIME: "+MAX_RSP_TIME);
|
||||
}
|
||||
events = new LinkedList<Event>();
|
||||
logger.config ("HttpServer created "+protocol+" "+ addr);
|
||||
logger.log (Level.DEBUG, "HttpServer created "+protocol+" "+ addr);
|
||||
}
|
||||
|
||||
public void bind (InetSocketAddress addr, int backlog) throws IOException {
|
||||
@ -211,7 +211,7 @@ class ServerImpl implements TimeSource {
|
||||
dispatcherThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
logger.log(Level.FINER, "ServerImpl.stop: ", e);
|
||||
logger.log (Level.TRACE, "ServerImpl.stop: ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -224,7 +224,7 @@ class ServerImpl implements TimeSource {
|
||||
}
|
||||
HttpContextImpl context = new HttpContextImpl (protocol, path, handler, this);
|
||||
contexts.add (context);
|
||||
logger.config ("context created: " + path);
|
||||
logger.log (Level.DEBUG, "context created: " + path);
|
||||
return context;
|
||||
}
|
||||
|
||||
@ -234,7 +234,7 @@ class ServerImpl implements TimeSource {
|
||||
}
|
||||
HttpContextImpl context = new HttpContextImpl (protocol, path, null, this);
|
||||
contexts.add (context);
|
||||
logger.config ("context created: " + path);
|
||||
logger.log (Level.DEBUG, "context created: " + path);
|
||||
return context;
|
||||
}
|
||||
|
||||
@ -243,7 +243,7 @@ class ServerImpl implements TimeSource {
|
||||
throw new NullPointerException ("null path parameter");
|
||||
}
|
||||
contexts.remove (protocol, path);
|
||||
logger.config ("context removed: " + path);
|
||||
logger.log (Level.DEBUG, "context removed: " + path);
|
||||
}
|
||||
|
||||
public synchronized void removeContext (HttpContext context) throws IllegalArgumentException {
|
||||
@ -251,7 +251,7 @@ class ServerImpl implements TimeSource {
|
||||
throw new IllegalArgumentException ("wrong HttpContext type");
|
||||
}
|
||||
contexts.remove ((HttpContextImpl)context);
|
||||
logger.config ("context removed: " + context.getPath());
|
||||
logger.log (Level.DEBUG, "context removed: " + context.getPath());
|
||||
}
|
||||
|
||||
public InetSocketAddress getAddress() {
|
||||
@ -310,7 +310,7 @@ class ServerImpl implements TimeSource {
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.log (
|
||||
Level.FINER, "Dispatcher (1)", e
|
||||
Level.TRACE, "Dispatcher (1)", e
|
||||
);
|
||||
c.close();
|
||||
}
|
||||
@ -331,7 +331,7 @@ class ServerImpl implements TimeSource {
|
||||
idleConnections.add (c);
|
||||
} catch (IOException e) {
|
||||
dprint(e);
|
||||
logger.log(Level.FINER, "Dispatcher(8)", e);
|
||||
logger.log (Level.TRACE, "Dispatcher(8)", e);
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
@ -416,9 +416,9 @@ class ServerImpl implements TimeSource {
|
||||
// call the selector just to process the cancelled keys
|
||||
selector.selectNow();
|
||||
} catch (IOException e) {
|
||||
logger.log (Level.FINER, "Dispatcher (4)", e);
|
||||
logger.log (Level.TRACE, "Dispatcher (4)", e);
|
||||
} catch (Exception e) {
|
||||
logger.log (Level.FINER, "Dispatcher (7)", e);
|
||||
logger.log (Level.TRACE, "Dispatcher (7)", e);
|
||||
}
|
||||
}
|
||||
try {selector.close(); } catch (Exception e) {}
|
||||
@ -427,7 +427,7 @@ class ServerImpl implements TimeSource {
|
||||
private void handleException (SelectionKey key, Exception e) {
|
||||
HttpConnection conn = (HttpConnection)key.attachment();
|
||||
if (e != null) {
|
||||
logger.log (Level.FINER, "Dispatcher (2)", e);
|
||||
logger.log (Level.TRACE, "Dispatcher (2)", e);
|
||||
}
|
||||
closeConnection(conn);
|
||||
}
|
||||
@ -439,10 +439,10 @@ class ServerImpl implements TimeSource {
|
||||
Exchange t = new Exchange (chan, protocol, conn);
|
||||
executor.execute (t);
|
||||
} catch (HttpError e1) {
|
||||
logger.log (Level.FINER, "Dispatcher (4)", e1);
|
||||
logger.log (Level.TRACE, "Dispatcher (4)", e1);
|
||||
closeConnection(conn);
|
||||
} catch (IOException e) {
|
||||
logger.log (Level.FINER, "Dispatcher (5)", e);
|
||||
logger.log (Level.TRACE, "Dispatcher (5)", e);
|
||||
closeConnection(conn);
|
||||
}
|
||||
}
|
||||
@ -522,7 +522,8 @@ class ServerImpl implements TimeSource {
|
||||
newconnection = true;
|
||||
if (https) {
|
||||
if (sslContext == null) {
|
||||
logger.warning ("SSL connection received. No https contxt created");
|
||||
logger.log (Level.WARNING,
|
||||
"SSL connection received. No https contxt created");
|
||||
throw new HttpError ("No SSL context established");
|
||||
}
|
||||
sslStreams = new SSLStreams (ServerImpl.this, sslContext, chan);
|
||||
@ -657,7 +658,7 @@ class ServerImpl implements TimeSource {
|
||||
}
|
||||
|
||||
} catch (IOException e1) {
|
||||
logger.log (Level.FINER, "ServerImpl.Exchange (1)", e1);
|
||||
logger.log (Level.TRACE, "ServerImpl.Exchange (1)", e1);
|
||||
closeConnection(connection);
|
||||
} catch (NumberFormatException e3) {
|
||||
reject (Code.HTTP_BAD_REQUEST,
|
||||
@ -666,7 +667,7 @@ class ServerImpl implements TimeSource {
|
||||
reject (Code.HTTP_BAD_REQUEST,
|
||||
requestLine, "URISyntaxException thrown");
|
||||
} catch (Exception e4) {
|
||||
logger.log (Level.FINER, "ServerImpl.Exchange (2)", e4);
|
||||
logger.log (Level.TRACE, "ServerImpl.Exchange (2)", e4);
|
||||
closeConnection(connection);
|
||||
}
|
||||
}
|
||||
@ -722,7 +723,7 @@ class ServerImpl implements TimeSource {
|
||||
closeConnection(connection);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.log (Level.FINER, "ServerImpl.sendReply", e);
|
||||
logger.log (Level.TRACE, "ServerImpl.sendReply", e);
|
||||
closeConnection(connection);
|
||||
}
|
||||
}
|
||||
@ -730,7 +731,7 @@ class ServerImpl implements TimeSource {
|
||||
}
|
||||
|
||||
void logReply (int code, String requestStr, String text) {
|
||||
if (!logger.isLoggable(Level.FINE)) {
|
||||
if (!logger.isLoggable(Level.DEBUG)) {
|
||||
return;
|
||||
}
|
||||
if (text == null) {
|
||||
@ -744,7 +745,7 @@ class ServerImpl implements TimeSource {
|
||||
}
|
||||
String message = r + " [" + code + " " +
|
||||
Code.msg(code) + "] ("+text+")";
|
||||
logger.fine (message);
|
||||
logger.log (Level.DEBUG, message);
|
||||
}
|
||||
|
||||
long getTicks() {
|
||||
@ -843,7 +844,7 @@ class ServerImpl implements TimeSource {
|
||||
}
|
||||
}
|
||||
for (HttpConnection c : toClose) {
|
||||
logger.log (Level.FINE, "closing: no request: " + c);
|
||||
logger.log (Level.DEBUG, "closing: no request: " + c);
|
||||
reqConnections.remove (c);
|
||||
allConnections.remove (c);
|
||||
c.close();
|
||||
@ -859,7 +860,7 @@ class ServerImpl implements TimeSource {
|
||||
}
|
||||
}
|
||||
for (HttpConnection c : toClose) {
|
||||
logger.log (Level.FINE, "closing: no response: " + c);
|
||||
logger.log (Level.DEBUG, "closing: no response: " + c);
|
||||
rspConnections.remove (c);
|
||||
allConnections.remove (c);
|
||||
c.close();
|
||||
@ -870,13 +871,13 @@ class ServerImpl implements TimeSource {
|
||||
}
|
||||
|
||||
void logStackTrace (String s) {
|
||||
logger.finest (s);
|
||||
logger.log (Level.TRACE, s);
|
||||
StringBuilder b = new StringBuilder ();
|
||||
StackTraceElement[] e = Thread.currentThread().getStackTrace();
|
||||
for (int i=0; i<e.length; i++) {
|
||||
b.append (e[i].toString()).append("\n");
|
||||
}
|
||||
logger.finest (b.toString());
|
||||
logger.log (Level.TRACE, b.toString());
|
||||
}
|
||||
|
||||
static long getTimeMillis(long secs) {
|
||||
|
||||
@ -50,6 +50,9 @@ import java.util.Map.Entry;
|
||||
|
||||
import jdk.security.jarsigner.JarSigner;
|
||||
import jdk.security.jarsigner.JarSignerException;
|
||||
import sun.security.pkcs.PKCS7;
|
||||
import sun.security.pkcs.SignerInfo;
|
||||
import sun.security.timestamp.TimestampToken;
|
||||
import sun.security.tools.KeyStoreUtil;
|
||||
import sun.security.x509.*;
|
||||
import sun.security.util.*;
|
||||
@ -87,6 +90,15 @@ public class Main {
|
||||
|
||||
private static final long SIX_MONTHS = 180*24*60*60*1000L; //milliseconds
|
||||
|
||||
private static final DisabledAlgorithmConstraints DISABLED_CHECK =
|
||||
new DisabledAlgorithmConstraints(
|
||||
DisabledAlgorithmConstraints.PROPERTY_JAR_DISABLED_ALGS);
|
||||
|
||||
private static final Set<CryptoPrimitive> DIGEST_PRIMITIVE_SET = Collections
|
||||
.unmodifiableSet(EnumSet.of(CryptoPrimitive.MESSAGE_DIGEST));
|
||||
private static final Set<CryptoPrimitive> SIG_PRIMITIVE_SET = Collections
|
||||
.unmodifiableSet(EnumSet.of(CryptoPrimitive.SIGNATURE));
|
||||
|
||||
// Attention:
|
||||
// This is the entry that get launched by the security tool jarsigner.
|
||||
public static void main(String args[]) throws Exception {
|
||||
@ -163,6 +175,8 @@ public class Main {
|
||||
|
||||
private Throwable chainNotValidatedReason = null;
|
||||
|
||||
private boolean seeWeak = false;
|
||||
|
||||
CertificateFactory certificateFactory;
|
||||
CertPathValidator validator;
|
||||
PKIXParameters pkixParameters;
|
||||
@ -628,6 +642,10 @@ public class Main {
|
||||
{
|
||||
boolean anySigned = false; // if there exists entry inside jar signed
|
||||
JarFile jf = null;
|
||||
Map<String,String> digestMap = new HashMap<>();
|
||||
Map<String,PKCS7> sigMap = new HashMap<>();
|
||||
Map<String,String> sigNameMap = new HashMap<>();
|
||||
Map<String,String> unparsableSignatures = new HashMap<>();
|
||||
|
||||
try {
|
||||
jf = new JarFile(jarName, true);
|
||||
@ -638,16 +656,44 @@ public class Main {
|
||||
while (entries.hasMoreElements()) {
|
||||
JarEntry je = entries.nextElement();
|
||||
entriesVec.addElement(je);
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = jf.getInputStream(je);
|
||||
while (is.read(buffer, 0, buffer.length) != -1) {
|
||||
// we just read. this will throw a SecurityException
|
||||
// if a signature/digest check fails.
|
||||
}
|
||||
} finally {
|
||||
if (is != null) {
|
||||
is.close();
|
||||
try (InputStream is = jf.getInputStream(je)) {
|
||||
String name = je.getName();
|
||||
if (signatureRelated(name)
|
||||
&& SignatureFileVerifier.isBlockOrSF(name)) {
|
||||
String alias = name.substring(name.lastIndexOf('/') + 1,
|
||||
name.lastIndexOf('.'));
|
||||
try {
|
||||
if (name.endsWith(".SF")) {
|
||||
Manifest sf = new Manifest(is);
|
||||
boolean found = false;
|
||||
for (Object obj : sf.getMainAttributes().keySet()) {
|
||||
String key = obj.toString();
|
||||
if (key.endsWith("-Digest-Manifest")) {
|
||||
digestMap.put(alias,
|
||||
key.substring(0, key.length() - 16));
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
unparsableSignatures.putIfAbsent(alias,
|
||||
String.format(
|
||||
rb.getString("history.unparsable"),
|
||||
name));
|
||||
}
|
||||
} else {
|
||||
sigNameMap.put(alias, name);
|
||||
sigMap.put(alias, new PKCS7(is));
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
unparsableSignatures.putIfAbsent(alias, String.format(
|
||||
rb.getString("history.unparsable"), name));
|
||||
}
|
||||
} else {
|
||||
while (is.read(buffer, 0, buffer.length) != -1) {
|
||||
// we just read. this will throw a SecurityException
|
||||
// if a signature/digest check fails.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -805,10 +851,11 @@ public class Main {
|
||||
System.out.println(rb.getString(
|
||||
".X.not.signed.by.specified.alias.es."));
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
if (man == null)
|
||||
if (man == null) {
|
||||
System.out.println();
|
||||
System.out.println(rb.getString("no.manifest."));
|
||||
}
|
||||
|
||||
// If signer is a trusted cert or private entry in user's own
|
||||
// keystore, it can be self-signed.
|
||||
@ -816,8 +863,99 @@ public class Main {
|
||||
signerSelfSigned = false;
|
||||
}
|
||||
|
||||
// Even if the verbose option is not specified, all out strings
|
||||
// must be generated so seeWeak can be updated.
|
||||
if (!digestMap.isEmpty()
|
||||
|| !sigMap.isEmpty()
|
||||
|| !unparsableSignatures.isEmpty()) {
|
||||
if (verbose != null) {
|
||||
System.out.println();
|
||||
}
|
||||
for (String s : sigMap.keySet()) {
|
||||
if (!digestMap.containsKey(s)) {
|
||||
unparsableSignatures.putIfAbsent(s, String.format(
|
||||
rb.getString("history.nosf"), s));
|
||||
}
|
||||
}
|
||||
for (String s : digestMap.keySet()) {
|
||||
PKCS7 p7 = sigMap.get(s);
|
||||
if (p7 != null) {
|
||||
String history;
|
||||
try {
|
||||
SignerInfo si = p7.getSignerInfos()[0];
|
||||
X509Certificate signer = si.getCertificate(p7);
|
||||
String digestAlg = digestMap.get(s);
|
||||
String sigAlg = AlgorithmId.makeSigAlg(
|
||||
si.getDigestAlgorithmId().getName(),
|
||||
si.getDigestEncryptionAlgorithmId().getName());
|
||||
PublicKey key = signer.getPublicKey();
|
||||
PKCS7 tsToken = si.getTsToken();
|
||||
if (tsToken != null) {
|
||||
SignerInfo tsSi = tsToken.getSignerInfos()[0];
|
||||
X509Certificate tsSigner = tsSi.getCertificate(tsToken);
|
||||
byte[] encTsTokenInfo = tsToken.getContentInfo().getData();
|
||||
TimestampToken tsTokenInfo = new TimestampToken(encTsTokenInfo);
|
||||
PublicKey tsKey = tsSigner.getPublicKey();
|
||||
String tsDigestAlg = tsTokenInfo.getHashAlgorithm().getName();
|
||||
String tsSigAlg = AlgorithmId.makeSigAlg(
|
||||
tsSi.getDigestAlgorithmId().getName(),
|
||||
tsSi.getDigestEncryptionAlgorithmId().getName());
|
||||
Calendar c = Calendar.getInstance(
|
||||
TimeZone.getTimeZone("UTC"),
|
||||
Locale.getDefault(Locale.Category.FORMAT));
|
||||
c.setTime(tsTokenInfo.getDate());
|
||||
history = String.format(
|
||||
rb.getString("history.with.ts"),
|
||||
signer.getSubjectX500Principal(),
|
||||
withWeak(digestAlg, DIGEST_PRIMITIVE_SET),
|
||||
withWeak(sigAlg, SIG_PRIMITIVE_SET),
|
||||
withWeak(key),
|
||||
c,
|
||||
tsSigner.getSubjectX500Principal(),
|
||||
withWeak(tsDigestAlg, DIGEST_PRIMITIVE_SET),
|
||||
withWeak(tsSigAlg, SIG_PRIMITIVE_SET),
|
||||
withWeak(tsKey));
|
||||
} else {
|
||||
history = String.format(
|
||||
rb.getString("history.without.ts"),
|
||||
signer.getSubjectX500Principal(),
|
||||
withWeak(digestAlg, DIGEST_PRIMITIVE_SET),
|
||||
withWeak(sigAlg, SIG_PRIMITIVE_SET),
|
||||
withWeak(key));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// The only usage of sigNameMap, remember the name
|
||||
// of the block file if it's invalid.
|
||||
history = String.format(
|
||||
rb.getString("history.unparsable"),
|
||||
sigNameMap.get(s));
|
||||
}
|
||||
if (verbose != null) {
|
||||
System.out.println(history);
|
||||
}
|
||||
} else {
|
||||
unparsableSignatures.putIfAbsent(s, String.format(
|
||||
rb.getString("history.nobk"), s));
|
||||
}
|
||||
}
|
||||
if (verbose != null) {
|
||||
for (String s : unparsableSignatures.keySet()) {
|
||||
System.out.println(unparsableSignatures.get(s));
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
if (!anySigned) {
|
||||
if (hasSignature) {
|
||||
if (seeWeak) {
|
||||
if (verbose != null) {
|
||||
System.out.println(rb.getString("jar.treated.unsigned.see.weak.verbose"));
|
||||
System.out.println("\n " +
|
||||
DisabledAlgorithmConstraints.PROPERTY_JAR_DISABLED_ALGS +
|
||||
"=" + Security.getProperty(DisabledAlgorithmConstraints.PROPERTY_JAR_DISABLED_ALGS));
|
||||
} else {
|
||||
System.out.println(rb.getString("jar.treated.unsigned.see.weak"));
|
||||
}
|
||||
} else if (hasSignature) {
|
||||
System.out.println(rb.getString("jar.treated.unsigned"));
|
||||
} else {
|
||||
System.out.println(rb.getString("jar.is.unsigned"));
|
||||
@ -845,7 +983,9 @@ public class Main {
|
||||
if (weakAlg != 0) {
|
||||
// In fact, jarsigner verification did not catch this
|
||||
// since it has not read the JarFile content itself.
|
||||
// Everything is done with JarFile API.
|
||||
// Everything is done with JarFile API. The signing
|
||||
// history (digestMap etc) will show these info and
|
||||
// print out proper warnings.
|
||||
}
|
||||
|
||||
if (badKeyUsage) {
|
||||
@ -936,6 +1076,26 @@ public class Main {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
private String withWeak(String alg, Set<CryptoPrimitive> primitiveSet) {
|
||||
if (DISABLED_CHECK.permits(primitiveSet, alg, null)) {
|
||||
return alg;
|
||||
} else {
|
||||
seeWeak = true;
|
||||
return String.format(rb.getString("with.weak"), alg);
|
||||
}
|
||||
}
|
||||
|
||||
private String withWeak(PublicKey key) {
|
||||
if (DISABLED_CHECK.permits(SIG_PRIMITIVE_SET, key)) {
|
||||
return String.format(
|
||||
rb.getString("key.bit"), KeyUtil.getKeySize(key));
|
||||
} else {
|
||||
seeWeak = true;
|
||||
return String.format(
|
||||
rb.getString("key.bit.weak"), KeyUtil.getKeySize(key));
|
||||
}
|
||||
}
|
||||
|
||||
private static MessageFormat validityTimeForm = null;
|
||||
private static MessageFormat notYetTimeForm = null;
|
||||
private static MessageFormat expiredTimeForm = null;
|
||||
@ -1125,22 +1285,22 @@ public class Main {
|
||||
void signJar(String jarName, String alias)
|
||||
throws Exception {
|
||||
|
||||
DisabledAlgorithmConstraints dac =
|
||||
new DisabledAlgorithmConstraints(
|
||||
DisabledAlgorithmConstraints.PROPERTY_CERTPATH_DISABLED_ALGS);
|
||||
|
||||
if (digestalg != null && !dac.permits(
|
||||
Collections.singleton(CryptoPrimitive.MESSAGE_DIGEST), digestalg, null)) {
|
||||
if (digestalg != null && !DISABLED_CHECK.permits(
|
||||
DIGEST_PRIMITIVE_SET, digestalg, null)) {
|
||||
weakAlg |= 1;
|
||||
}
|
||||
if (tSADigestAlg != null && !dac.permits(
|
||||
Collections.singleton(CryptoPrimitive.MESSAGE_DIGEST), tSADigestAlg, null)) {
|
||||
if (tSADigestAlg != null && !DISABLED_CHECK.permits(
|
||||
DIGEST_PRIMITIVE_SET, tSADigestAlg, null)) {
|
||||
weakAlg |= 4;
|
||||
}
|
||||
if (sigalg != null && !dac.permits(
|
||||
Collections.singleton(CryptoPrimitive.SIGNATURE), sigalg, null)) {
|
||||
if (sigalg != null && !DISABLED_CHECK.permits(
|
||||
SIG_PRIMITIVE_SET , sigalg, null)) {
|
||||
weakAlg |= 2;
|
||||
}
|
||||
if (!DISABLED_CHECK.permits(
|
||||
SIG_PRIMITIVE_SET, privateKey)) {
|
||||
weakAlg |= 8;
|
||||
}
|
||||
|
||||
boolean aliasUsed = false;
|
||||
X509Certificate tsaCert = null;
|
||||
@ -1385,6 +1545,11 @@ public class Main {
|
||||
rb.getString("The.1.algorithm.specified.for.the.2.option.is.considered.a.security.risk."),
|
||||
tSADigestAlg, "-tsadigestalg"));
|
||||
}
|
||||
if ((weakAlg & 8) == 8) {
|
||||
System.out.println(String.format(
|
||||
rb.getString("The.1.signing.key.has.a.keysize.of.2.which.is.considered.a.security.risk."),
|
||||
privateKey.getAlgorithm(), KeyUtil.getKeySize(privateKey)));
|
||||
}
|
||||
} else {
|
||||
System.out.println(rb.getString("jar.signed."));
|
||||
}
|
||||
|
||||
@ -145,11 +145,26 @@ public class Resources extends java.util.ListResourceBundle {
|
||||
{"jar.is.unsigned",
|
||||
"jar is unsigned."},
|
||||
{"jar.treated.unsigned",
|
||||
"Signature not parsable or verifiable. The jar will be treated as unsigned. The jar may have been signed with a weak algorithm that is now disabled. For more information, rerun jarsigner with debug enabled (-J-Djava.security.debug=jar)."},
|
||||
"WARNING: Signature is either not parsable or not verifiable, and the jar will be treated as unsigned. For more information, re-run jarsigner with debug enabled (-J-Djava.security.debug=jar)."},
|
||||
{"jar.treated.unsigned.see.weak",
|
||||
"The jar will be treated as unsigned, because it is signed with a weak algorithm that is now disabled.\n\nRe-run jarsigner with the -verbose option for more details."},
|
||||
{"jar.treated.unsigned.see.weak.verbose",
|
||||
"WARNING: The jar will be treated as unsigned, because it is signed with a weak algorithm that is now disabled by the security property:"},
|
||||
{"jar.signed.", "jar signed."},
|
||||
{"jar.signed.with.signer.errors.", "jar signed, with signer errors."},
|
||||
{"jar.verified.", "jar verified."},
|
||||
{"jar.verified.with.signer.errors.", "jar verified, with signer errors."},
|
||||
|
||||
{"history.with.ts", "- Signed by \"%1$s\"\n Digest algorithm: %2$s\n Signature algorithm: %3$s, %4$s\n Timestamped by \"%6$s\" on %5$tc\n Timestamp digest algorithm: %7$s\n Timestamp signature algorithm: %8$s, %9$s"},
|
||||
{"history.without.ts", "- Signed by \"%1$s\"\n Digest algorithm: %2$s\n Signature algorithm: %3$s, %4$s"},
|
||||
{"history.unparsable", "- Unparsable signature-related file %s"},
|
||||
{"history.nosf", "- Missing signature-related file META-INF/%s.SF"},
|
||||
{"history.nobk", "- Missing block file for signature-related file META-INF/%s.SF"},
|
||||
|
||||
{"with.weak", "%s (weak)"},
|
||||
{"key.bit", "%d-bit key"},
|
||||
{"key.bit.weak", "%d-bit key (weak)"},
|
||||
|
||||
{"jarsigner.", "jarsigner: "},
|
||||
{"signature.filename.must.consist.of.the.following.characters.A.Z.0.9.or.",
|
||||
"signature filename must consist of the following characters: A-Z, 0-9, _ or -"},
|
||||
@ -248,6 +263,8 @@ public class Resources extends java.util.ListResourceBundle {
|
||||
"The signer's certificate is self-signed."},
|
||||
{"The.1.algorithm.specified.for.the.2.option.is.considered.a.security.risk.",
|
||||
"The %1$s algorithm specified for the %2$s option is considered a security risk."},
|
||||
{"The.1.signing.key.has.a.keysize.of.2.which.is.considered.a.security.risk.",
|
||||
"The %s signing key has a keysize of %d which is considered a security risk."},
|
||||
{"This.jar.contains.entries.whose.certificate.chain.is.not.validated.reason.1",
|
||||
"This jar contains entries whose certificate chain is not validated. Reason: %s"},
|
||||
{"no.timestamp.signing",
|
||||
|
||||
@ -80,6 +80,7 @@ class Main {
|
||||
String fname, mname, ename;
|
||||
String zname = "";
|
||||
String rootjar = null;
|
||||
Set<String> concealedPackages = new HashSet<>();
|
||||
|
||||
private static final int BASE_VERSION = 0;
|
||||
|
||||
@ -821,22 +822,21 @@ class Main {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Set<String> findPackages(ZipFile zf) {
|
||||
return zf.stream()
|
||||
.filter(e -> e.getName().endsWith(".class"))
|
||||
.map(e -> toPackageName(e))
|
||||
.filter(pkg -> pkg.length() > 0)
|
||||
.distinct()
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private static String toPackageName(ZipEntry entry) {
|
||||
return toPackageName(entry.getName());
|
||||
}
|
||||
|
||||
private static String toPackageName(String path) {
|
||||
assert path.endsWith(".class");
|
||||
int index = path.lastIndexOf('/');
|
||||
int index;
|
||||
if (path.startsWith(VERSIONS_DIR)) {
|
||||
index = path.indexOf('/', VERSIONS_DIR.length());
|
||||
if (index <= 0) {
|
||||
return "";
|
||||
}
|
||||
path = path.substring(index + 1);
|
||||
}
|
||||
index = path.lastIndexOf('/');
|
||||
if (index != -1) {
|
||||
return path.substring(0, index).replace('/', '.');
|
||||
} else {
|
||||
@ -875,7 +875,7 @@ class Main {
|
||||
entryMap.put(entryName, entry);
|
||||
} else if (entries.add(entry)) {
|
||||
jarEntries.add(entryName);
|
||||
if (entry.basename.endsWith(".class") && !entryName.startsWith(VERSIONS_DIR))
|
||||
if (entry.basename.endsWith(".class"))
|
||||
packages.add(toPackageName(entry.basename));
|
||||
if (isUpdate)
|
||||
entryMap.put(entryName, entry);
|
||||
@ -1068,7 +1068,7 @@ class Main {
|
||||
}
|
||||
|
||||
jarEntries.add(name);
|
||||
if (name.endsWith(".class") && !(name.startsWith(VERSIONS_DIR)))
|
||||
if (name.endsWith(".class"))
|
||||
packages.add(toPackageName(name));
|
||||
}
|
||||
}
|
||||
@ -1761,6 +1761,13 @@ class Main {
|
||||
err.println(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a warning message
|
||||
*/
|
||||
void warn(String s) {
|
||||
err.println(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main routine to start program.
|
||||
*/
|
||||
@ -1975,24 +1982,30 @@ class Main {
|
||||
ByteBuffer bb = ByteBuffer.wrap(moduleInfos.get(MODULE_INFO));
|
||||
ModuleDescriptor rd = ModuleDescriptor.read(bb);
|
||||
|
||||
Set<String> exports = rd.exports()
|
||||
.stream()
|
||||
.map(Exports::source)
|
||||
.collect(toSet());
|
||||
|
||||
Set<String> conceals = packages.stream()
|
||||
.filter(p -> !exports.contains(p))
|
||||
.collect(toSet());
|
||||
concealedPackages = findConcealedPackages(rd);
|
||||
|
||||
for (Map.Entry<String,byte[]> e: moduleInfos.entrySet()) {
|
||||
ModuleDescriptor vd = ModuleDescriptor.read(ByteBuffer.wrap(e.getValue()));
|
||||
if (!(isValidVersionedDescriptor(vd, rd)))
|
||||
return false;
|
||||
e.setValue(extendedInfoBytes(rd, vd, e.getValue(), conceals));
|
||||
e.setValue(extendedInfoBytes(rd, vd, e.getValue(), concealedPackages));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private Set<String> findConcealedPackages(ModuleDescriptor md){
|
||||
Objects.requireNonNull(md);
|
||||
|
||||
Set<String> exports = md.exports()
|
||||
.stream()
|
||||
.map(Exports::source)
|
||||
.collect(toSet());
|
||||
|
||||
return packages.stream()
|
||||
.filter(p -> !exports.contains(p))
|
||||
.collect(toSet());
|
||||
}
|
||||
|
||||
private static boolean isPlatformModule(String name) {
|
||||
return name.startsWith("java.") || name.startsWith("jdk.");
|
||||
}
|
||||
|
||||
@ -152,9 +152,13 @@ final class Validator implements Consumer<JarEntry> {
|
||||
return;
|
||||
}
|
||||
if (fp.isPublicClass()) {
|
||||
main.error(Main.formatMsg("error.validator.new.public.class", entryName));
|
||||
isValid = false;
|
||||
return;
|
||||
if (!isConcealed(internalName)) {
|
||||
main.error(Main.formatMsg("error.validator.new.public.class", entryName));
|
||||
isValid = false;
|
||||
return;
|
||||
}
|
||||
main.warn(Main.formatMsg("warn.validator.concealed.public.class", entryName));
|
||||
debug("%s is a public class entry in a concealed package", entryName);
|
||||
}
|
||||
debug("%s is a non-public class entry", entryName);
|
||||
fps.put(internalName, fp);
|
||||
@ -169,7 +173,7 @@ final class Validator implements Consumer<JarEntry> {
|
||||
|
||||
// are the two classes/resources identical?
|
||||
if (fp.isIdentical(matchFp)) {
|
||||
main.error(Main.formatMsg("error.validator.identical.entry", entryName));
|
||||
main.warn(Main.formatMsg("warn.validator.identical.entry", entryName));
|
||||
return; // it's okay, just takes up room
|
||||
}
|
||||
debug("sha1 not equal -- different bytes");
|
||||
@ -204,7 +208,7 @@ final class Validator implements Consumer<JarEntry> {
|
||||
}
|
||||
debug("%s is a resource", entryName);
|
||||
|
||||
main.error(Main.formatMsg("error.validator.resources.with.same.name", entryName));
|
||||
main.warn(Main.formatMsg("warn.validator.resources.with.same.name", entryName));
|
||||
fps.put(internalName, fp);
|
||||
return;
|
||||
}
|
||||
@ -235,6 +239,15 @@ final class Validator implements Consumer<JarEntry> {
|
||||
return entryName.endsWith(".class") ? entryName.substring(0, entryName.length() - 6) : null;
|
||||
}
|
||||
|
||||
private boolean isConcealed(String internalName) {
|
||||
if (main.concealedPackages.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
int idx = internalName.lastIndexOf('/');
|
||||
String pkgName = idx != -1 ? internalName.substring(0, idx).replace('/', '.') : "";
|
||||
return main.concealedPackages.contains(pkgName);
|
||||
}
|
||||
|
||||
private void debug(String fmt, Object... args) {
|
||||
if (DEBUG) System.err.format(fmt, args);
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user