Merge
This commit is contained in:
commit
9c6aee1cdf
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2012, 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
|
||||
@ -622,11 +622,7 @@ public class DnsClient {
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
private static boolean debug = false;
|
||||
|
||||
public static void setDebug(boolean flag) {
|
||||
debug = flag;
|
||||
}
|
||||
private static final boolean debug = false;
|
||||
|
||||
private static void dprint(String mess) {
|
||||
if (debug) {
|
||||
|
@ -153,7 +153,7 @@ public class File
|
||||
/**
|
||||
* The FileSystem object representing the platform's local file system.
|
||||
*/
|
||||
static private FileSystem fs = FileSystem.getFileSystem();
|
||||
private static final FileSystem fs = FileSystem.getFileSystem();
|
||||
|
||||
/**
|
||||
* This abstract pathname's normalized pathname string. A normalized
|
||||
@ -162,13 +162,13 @@ public class File
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private String path;
|
||||
private final String path;
|
||||
|
||||
/**
|
||||
* The length of this abstract pathname's prefix, or zero if it has no
|
||||
* prefix.
|
||||
*/
|
||||
private transient int prefixLength;
|
||||
private final transient int prefixLength;
|
||||
|
||||
/**
|
||||
* Returns the length of this abstract pathname's prefix.
|
||||
@ -2023,10 +2023,28 @@ public class File
|
||||
char sep = s.readChar(); // read the previous separator char
|
||||
if (sep != separatorChar)
|
||||
pathField = pathField.replace(sep, separatorChar);
|
||||
this.path = fs.normalize(pathField);
|
||||
this.prefixLength = fs.prefixLength(this.path);
|
||||
String path = fs.normalize(pathField);
|
||||
UNSAFE.putObject(this, PATH_OFFSET, path);
|
||||
UNSAFE.putIntVolatile(this, PREFIX_LENGTH_OFFSET, fs.prefixLength(path));
|
||||
}
|
||||
|
||||
private static final long PATH_OFFSET;
|
||||
private static final long PREFIX_LENGTH_OFFSET;
|
||||
private static final sun.misc.Unsafe UNSAFE;
|
||||
static {
|
||||
try {
|
||||
sun.misc.Unsafe unsafe = sun.misc.Unsafe.getUnsafe();
|
||||
PATH_OFFSET = unsafe.objectFieldOffset(
|
||||
File.class.getDeclaredField("path"));
|
||||
PREFIX_LENGTH_OFFSET = unsafe.objectFieldOffset(
|
||||
File.class.getDeclaredField("prefixLength"));
|
||||
UNSAFE = unsafe;
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** use serialVersionUID from JDK 1.0.2 for interoperability */
|
||||
private static final long serialVersionUID = 301077366599181567L;
|
||||
|
||||
|
@ -81,6 +81,22 @@ import sun.misc.DoubleConsts;
|
||||
* floating-point approximation. Not all approximations that have 1
|
||||
* ulp accuracy will automatically meet the monotonicity requirements.
|
||||
*
|
||||
* <p>
|
||||
* The platform uses signed two's complement integer arithmetic with
|
||||
* int and long primitive types. The developer should choose
|
||||
* the primitive type to ensure that arithmetic operations consistently
|
||||
* produce correct results, which in some cases means the operations
|
||||
* will not overflow the range of values of the computation.
|
||||
* The best practice is to choose the primitive type and algorithm to avoid
|
||||
* overflow. In cases where the size is {@code int} or {@code long} and
|
||||
* overflow errors need to be detected, the methods {@code addExact},
|
||||
* {@code subtractExact}, {@code multiplyExact}, and {@code toIntExact}
|
||||
* throw an {@code ArithmeticException} when the results overflow.
|
||||
* For other arithmetic operations such as divide, absolute value,
|
||||
* increment, decrement, and negation overflow occurs only with
|
||||
* a specific minimum or maximum value and should be checked against
|
||||
* the minimum or maximum as appropriate.
|
||||
*
|
||||
* @author unascribed
|
||||
* @author Joseph D. Darcy
|
||||
* @since JDK1.0
|
||||
@ -718,6 +734,137 @@ public final class Math {
|
||||
return rnd.nextDouble();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of its arguments,
|
||||
* throwing an exception if the result overflows an {@code int}.
|
||||
*
|
||||
* @param x the first value
|
||||
* @param y the second value
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows an int
|
||||
*/
|
||||
public static int addExact(int x, int y) {
|
||||
int r = x + y;
|
||||
// HD 2-12 Overflow iff both arguments have the opposite sign of the result
|
||||
if (((x ^ r) & (y ^ r)) < 0) {
|
||||
throw new ArithmeticException("integer overflow");
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of its arguments,
|
||||
* throwing an exception if the result overflows a {@code long}.
|
||||
*
|
||||
* @param x the first value
|
||||
* @param y the second value
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows a long
|
||||
*/
|
||||
public static long addExact(long x, long y) {
|
||||
long r = x + y;
|
||||
// HD 2-12 Overflow iff both arguments have the opposite sign of the result
|
||||
if (((x ^ r) & (y ^ r)) < 0) {
|
||||
throw new ArithmeticException("long overflow");
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the difference of the arguments,
|
||||
* throwing an exception if the result overflows an {@code int}.
|
||||
*
|
||||
* @param x the first value
|
||||
* @param y the second value to subtract from the first
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows an int
|
||||
*/
|
||||
public static int subtractExact(int x, int y) {
|
||||
int r = x - y;
|
||||
// HD 2-12 Overflow iff the arguments have different signs and
|
||||
// the sign of the result is different than the sign of x
|
||||
if (((x ^ y) & (x ^ r)) < 0) {
|
||||
throw new ArithmeticException("integer overflow");
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the difference of the arguments,
|
||||
* throwing an exception if the result overflows a {@code long}.
|
||||
*
|
||||
* @param x the first value
|
||||
* @param y the second value to subtract from the first
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows a long
|
||||
*/
|
||||
public static long subtractExact(long x, long y) {
|
||||
long r = x - y;
|
||||
// HD 2-12 Overflow iff the arguments have different signs and
|
||||
// the sign of the result is different than the sign of x
|
||||
if (((x ^ y) & (x ^ r)) < 0) {
|
||||
throw new ArithmeticException("long overflow");
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the product of the arguments,
|
||||
* throwing an exception if the result overflows an {@code int}.
|
||||
*
|
||||
* @param x the first value
|
||||
* @param y the second value
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows an int
|
||||
*/
|
||||
public static int multiplyExact(int x, int y) {
|
||||
long r = (long)x * (long)y;
|
||||
if ((int)r != r) {
|
||||
throw new ArithmeticException("long overflow");
|
||||
}
|
||||
return (int)r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the product of the arguments,
|
||||
* throwing an exception if the result overflows a {@code long}.
|
||||
*
|
||||
* @param x the first value
|
||||
* @param y the second value
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows a long
|
||||
*/
|
||||
public static long multiplyExact(long x, long y) {
|
||||
long r = x * y;
|
||||
long ax = Math.abs(x);
|
||||
long ay = Math.abs(y);
|
||||
if (((ax | ay) >>> 31 != 0)) {
|
||||
// Some bits greater than 2^31 that might cause overflow
|
||||
// Check the result using the divide operator
|
||||
// and check for the special case of Long.MIN_VALUE * -1
|
||||
if (((y != 0) && (r / y != x)) ||
|
||||
(x == Long.MIN_VALUE && y == -1)) {
|
||||
throw new ArithmeticException("long overflow");
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the {@code long} argument;
|
||||
* throwing an exception if the value overflows an {@code int}.
|
||||
*
|
||||
* @param value the long value
|
||||
* @return the argument as an int
|
||||
* @throws ArithmeticException if the {@code argument} overflows an int
|
||||
*/
|
||||
public static int toIntExact(long value) {
|
||||
if ((int)value != value) {
|
||||
throw new ArithmeticException("integer overflow");
|
||||
}
|
||||
return (int)value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute value of an {@code int} value.
|
||||
* If the argument is not negative, the argument is returned.
|
||||
@ -1737,7 +1884,7 @@ public final class Math {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@code d} ×
|
||||
* Returns {@code d} ×
|
||||
* 2<sup>{@code scaleFactor}</sup> rounded as if performed
|
||||
* by a single correctly rounded floating-point multiply to a
|
||||
* member of the double value set. See the Java
|
||||
@ -1844,7 +1991,7 @@ public final class Math {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@code f} ×
|
||||
* Returns {@code f} ×
|
||||
* 2<sup>{@code scaleFactor}</sup> rounded as if performed
|
||||
* by a single correctly rounded floating-point multiply to a
|
||||
* member of the float value set. See the Java
|
||||
|
@ -56,6 +56,22 @@ import sun.misc.DoubleConsts;
|
||||
* {@code sinh}, {@code cosh}, {@code tanh},
|
||||
* {@code hypot}, {@code expm1}, and {@code log1p}.
|
||||
*
|
||||
* <p>
|
||||
* The platform uses signed two's complement integer arithmetic with
|
||||
* int and long primitive types. The developer should choose
|
||||
* the primitive type to ensure that arithmetic operations consistently
|
||||
* produce correct results, which in some cases means the operations
|
||||
* will not overflow the range of values of the computation.
|
||||
* The best practice is to choose the primitive type and algorithm to avoid
|
||||
* overflow. In cases where the size is {@code int} or {@code long} and
|
||||
* overflow errors need to be detected, the methods {@code addExact},
|
||||
* {@code subtractExact}, {@code multiplyExact}, and {@code toIntExact}
|
||||
* throw an {@code ArithmeticException} when the results overflow.
|
||||
* For other arithmetic operations such as divide, absolute value,
|
||||
* increment, decrement, and negation overflow occurs only with
|
||||
* a specific minimum or maximum value and should be checked against
|
||||
* the minimum or maximum as appropriate.
|
||||
*
|
||||
* @author unascribed
|
||||
* @author Joseph D. Darcy
|
||||
* @since 1.3
|
||||
@ -699,7 +715,111 @@ public final class StrictMath {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute value of an {@code int} value..
|
||||
* Returns the sum of its arguments,
|
||||
* throwing an exception if the result overflows an {@code int}.
|
||||
*
|
||||
* @param x the first value
|
||||
* @param y the second value
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows an int
|
||||
* @see Math#addExact(int,int)
|
||||
* @since 1.8
|
||||
*/
|
||||
public static int addExact(int x, int y) {
|
||||
return Math.addExact(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of its arguments,
|
||||
* throwing an exception if the result overflows a {@code long}.
|
||||
*
|
||||
* @param x the first value
|
||||
* @param y the second value
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows a long
|
||||
* @see Math#addExact(long,long)
|
||||
* @since 1.8
|
||||
*/
|
||||
public static long addExact(long x, long y) {
|
||||
return Math.addExact(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the difference of the arguments,
|
||||
* throwing an exception if the result overflows an {@code int}.
|
||||
*
|
||||
* @param x the first value
|
||||
* @param y the second value to subtract from the first
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows an int
|
||||
* @see Math#subtractExact(int,int)
|
||||
* @since 1.8
|
||||
*/
|
||||
public static int subtractExact(int x, int y) {
|
||||
return Math.subtractExact(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the difference of the arguments,
|
||||
* throwing an exception if the result overflows a {@code long}.
|
||||
*
|
||||
* @param x the first value
|
||||
* @param y the second value to subtract from the first
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows a long
|
||||
* @see Math#subtractExact(long,long)
|
||||
* @since 1.8
|
||||
*/
|
||||
public static long subtractExact(long x, long y) {
|
||||
return Math.subtractExact(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the product of the arguments,
|
||||
* throwing an exception if the result overflows an {@code int}.
|
||||
*
|
||||
* @param x the first value
|
||||
* @param y the second value
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows an int
|
||||
* @see Math#multiplyExact(int,int)
|
||||
* @since 1.8
|
||||
*/
|
||||
public static int multiplyExact(int x, int y) {
|
||||
return Math.multiplyExact(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the product of the arguments,
|
||||
* throwing an exception if the result overflows a {@code long}.
|
||||
*
|
||||
* @param x the first value
|
||||
* @param y the second value
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows a long
|
||||
* @see Math#multiplyExact(long,long)
|
||||
* @since 1.8
|
||||
*/
|
||||
public static long multiplyExact(long x, long y) {
|
||||
return Math.multiplyExact(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of the {@code long} argument;
|
||||
* throwing an exception if the value overflows an {@code int}.
|
||||
*
|
||||
* @param value the long value
|
||||
* @return the argument as an int
|
||||
* @throws ArithmeticException if the {@code argument} overflows an int
|
||||
* @see Math#toIntExact(int)
|
||||
* @since 1.8
|
||||
*/
|
||||
public static int toIntExact(long value) {
|
||||
return Math.toIntExact(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute value of an {@code int} value.
|
||||
* If the argument is not negative, the argument is returned.
|
||||
* If the argument is negative, the negation of the argument is returned.
|
||||
*
|
||||
|
@ -1099,6 +1099,19 @@ public final class System {
|
||||
*/
|
||||
public static native String mapLibraryName(String libname);
|
||||
|
||||
/**
|
||||
* Create PrintStream for stdout/err based on encoding.
|
||||
*/
|
||||
private static PrintStream newPrintStream(FileOutputStream fos, String enc) {
|
||||
if (enc != null) {
|
||||
try {
|
||||
return new PrintStream(new BufferedOutputStream(fos, 128), true, enc);
|
||||
} catch (UnsupportedEncodingException uee) {}
|
||||
}
|
||||
return new PrintStream(new BufferedOutputStream(fos, 128), true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the system class. Called after thread initialization.
|
||||
*/
|
||||
@ -1139,8 +1152,9 @@ public final class System {
|
||||
FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
|
||||
FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
|
||||
setIn0(new BufferedInputStream(fdIn));
|
||||
setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));
|
||||
setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true));
|
||||
setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding")));
|
||||
setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding")));
|
||||
|
||||
// Load the zip library now in order to keep java.util.zip.ZipFile
|
||||
// from trying to use itself to load this library later.
|
||||
loadLibrary("zip");
|
||||
|
@ -44,8 +44,9 @@ class NativeThreadSet {
|
||||
//
|
||||
int add() {
|
||||
long th = NativeThread.current();
|
||||
if (th == -1)
|
||||
return -1;
|
||||
// 0 and -1 are treated as placeholders, not real thread handles
|
||||
if (th == 0)
|
||||
th = -1;
|
||||
synchronized (this) {
|
||||
int start = 0;
|
||||
if (used >= elts.length) {
|
||||
@ -71,8 +72,6 @@ class NativeThreadSet {
|
||||
// Removes the thread at the given index.
|
||||
//
|
||||
void remove(int i) {
|
||||
if (i < 0)
|
||||
return;
|
||||
synchronized (this) {
|
||||
elts[i] = 0;
|
||||
used--;
|
||||
@ -91,7 +90,8 @@ class NativeThreadSet {
|
||||
long th = elts[i];
|
||||
if (th == 0)
|
||||
continue;
|
||||
NativeThread.signal(th);
|
||||
if (th != -1)
|
||||
NativeThread.signal(th);
|
||||
if (--u == 0)
|
||||
break;
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ public class KeyTab implements KeyTabConstants {
|
||||
if (s == null) {
|
||||
return getInstance();
|
||||
} else {
|
||||
return getInstance0(s);
|
||||
return getInstance0(parse(s));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2012, 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
|
||||
@ -31,6 +31,7 @@ import java.util.*;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.KeyManagementException;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
@ -423,6 +424,17 @@ final class CipherSuite implements Comparable<CipherSuite> {
|
||||
// Is the cipher algorithm of Cipher Block Chaining (CBC) mode?
|
||||
final boolean isCBCMode;
|
||||
|
||||
// The secure random used to detect the cipher availability.
|
||||
private final static SecureRandom secureRandom;
|
||||
|
||||
static {
|
||||
try {
|
||||
secureRandom = JsseJce.getSecureRandom();
|
||||
} catch (KeyManagementException kme) {
|
||||
throw new RuntimeException(kme);
|
||||
}
|
||||
}
|
||||
|
||||
BulkCipher(String transformation, int keySize,
|
||||
int expandedKeySize, int ivSize, boolean allowed) {
|
||||
this.transformation = transformation;
|
||||
@ -505,7 +517,7 @@ final class CipherSuite implements Comparable<CipherSuite> {
|
||||
IvParameterSpec iv =
|
||||
new IvParameterSpec(new byte[cipher.ivSize]);
|
||||
cipher.newCipher(ProtocolVersion.DEFAULT,
|
||||
key, iv, null, true);
|
||||
key, iv, secureRandom, true);
|
||||
b = Boolean.TRUE;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
b = Boolean.FALSE;
|
||||
|
@ -2117,19 +2117,24 @@ public final class KeyTool {
|
||||
if (caks != null) {
|
||||
issuer = verifyCRL(caks, crl);
|
||||
if (issuer != null) {
|
||||
System.out.println("Verified by " + issuer + " in cacerts");
|
||||
out.printf(rb.getString(
|
||||
"verified.by.s.in.s"), issuer, "cacerts");
|
||||
out.println();
|
||||
}
|
||||
}
|
||||
if (issuer == null && keyStore != null) {
|
||||
issuer = verifyCRL(keyStore, crl);
|
||||
if (issuer != null) {
|
||||
System.out.println("Verified by " + issuer + " in keystore");
|
||||
out.printf(rb.getString(
|
||||
"verified.by.s.in.s"), issuer, "keystore");
|
||||
out.println();
|
||||
}
|
||||
}
|
||||
if (issuer == null) {
|
||||
out.println(rb.getString
|
||||
("STAR"));
|
||||
out.println("WARNING: not verified. Make sure -keystore and -alias are correct.");
|
||||
out.println(rb.getString
|
||||
("warning.not.verified.make.sure.keystore.is.correct"));
|
||||
out.println(rb.getString
|
||||
("STARNN"));
|
||||
}
|
||||
|
@ -409,6 +409,10 @@ public class Resources extends java.util.ListResourceBundle {
|
||||
{"Please.provide.keysize.for.secret.key.generation",
|
||||
"Please provide -keysize for secret key generation"},
|
||||
|
||||
{"verified.by.s.in.s", "Verified by %s in %s"},
|
||||
{"warning.not.verified.make.sure.keystore.is.correct",
|
||||
"WARNING: not verified. Make sure -keystore is correct."},
|
||||
|
||||
{"Extensions.", "Extensions: "},
|
||||
{".Empty.value.", "(Empty value)"},
|
||||
{"Extension.Request.", "Extension Request:"},
|
||||
|
@ -235,7 +235,14 @@ Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
|
||||
}
|
||||
PUTPROP(props, "file.encoding", sprops->encoding);
|
||||
PUTPROP(props, "sun.jnu.encoding", sprops->sun_jnu_encoding);
|
||||
if (sprops->sun_stdout_encoding != NULL) {
|
||||
PUTPROP(props, "sun.stdout.encoding", sprops->sun_stdout_encoding);
|
||||
}
|
||||
if (sprops->sun_stderr_encoding != NULL) {
|
||||
PUTPROP(props, "sun.stderr.encoding", sprops->sun_stderr_encoding);
|
||||
}
|
||||
PUTPROP(props, "file.encoding.pkg", "sun.io");
|
||||
|
||||
/* unicode_encoding specifies the default endianness */
|
||||
PUTPROP(props, "sun.io.unicode.encoding", sprops->unicode_encoding);
|
||||
PUTPROP(props, "sun.cpu.isalist",
|
||||
|
@ -66,6 +66,8 @@ typedef struct {
|
||||
char *display_variant;
|
||||
char *encoding;
|
||||
char *sun_jnu_encoding;
|
||||
char *sun_stdout_encoding;
|
||||
char *sun_stderr_encoding;
|
||||
char *timezone;
|
||||
|
||||
char *printerJob;
|
||||
|
@ -191,7 +191,7 @@ Java_sun_nio_ch_FileDispatcherImpl_lock0(JNIEnv *env, jobject this, jobject fdo,
|
||||
}
|
||||
lockResult = fcntl(fd, cmd, &fl);
|
||||
if (lockResult < 0) {
|
||||
if ((cmd == F_SETLK64) && (errno == EAGAIN))
|
||||
if ((cmd == F_SETLK64) && (errno == EAGAIN || errno == EACCES))
|
||||
return sun_nio_ch_FileDispatcherImpl_NO_LOCK;
|
||||
if (errno == EINTR)
|
||||
return sun_nio_ch_FileDispatcherImpl_INTERRUPTED;
|
||||
|
@ -31,7 +31,11 @@ package sun.nio.ch;
|
||||
|
||||
class NativeThread {
|
||||
|
||||
static long current() { return -1; }
|
||||
static long current() {
|
||||
// return 0 to ensure that async close of blocking sockets will close
|
||||
// the underlying socket.
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void signal(long nt) { }
|
||||
|
||||
|
@ -55,10 +55,11 @@ class SocketDispatcher extends NativeDispatcher
|
||||
return writev0(fd, address, len);
|
||||
}
|
||||
|
||||
void close(FileDescriptor fd) throws IOException {
|
||||
void preClose(FileDescriptor fd) throws IOException {
|
||||
preClose0(fd);
|
||||
}
|
||||
|
||||
void preClose(FileDescriptor fd) throws IOException {
|
||||
void close(FileDescriptor fd) throws IOException {
|
||||
close0(fd);
|
||||
}
|
||||
|
||||
@ -75,5 +76,7 @@ class SocketDispatcher extends NativeDispatcher
|
||||
static native long writev0(FileDescriptor fd, long address, int len)
|
||||
throws IOException;
|
||||
|
||||
static native void preClose0(FileDescriptor fd) throws IOException;
|
||||
|
||||
static native void close0(FileDescriptor fd) throws IOException;
|
||||
}
|
||||
|
@ -31,6 +31,9 @@
|
||||
#include <sys/timeb.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <Wincon.h>
|
||||
|
||||
#include "locale_str.h"
|
||||
#include "java_props.h"
|
||||
|
||||
@ -123,6 +126,17 @@ getEncodingInternal(LCID lcid)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char* getConsoleEncoding()
|
||||
{
|
||||
char* buf = malloc(16);
|
||||
int cp = GetConsoleCP();
|
||||
if (cp >= 874 && cp <= 950)
|
||||
sprintf(buf, "ms%d", cp);
|
||||
else
|
||||
sprintf(buf, "cp%d", cp);
|
||||
return buf;
|
||||
}
|
||||
|
||||
// Exported entries for AWT
|
||||
DllExport const char *
|
||||
getEncodingFromLangID(LANGID langID)
|
||||
@ -562,6 +576,7 @@ GetJavaProperties(JNIEnv* env)
|
||||
|
||||
{
|
||||
char * display_encoding;
|
||||
HANDLE hStdOutErr;
|
||||
|
||||
// Windows UI Language selection list only cares "language"
|
||||
// information of the UI Language. For example, the list
|
||||
@ -606,6 +621,20 @@ GetJavaProperties(JNIEnv* env)
|
||||
sprops.encoding = "MS950_HKSCS";
|
||||
sprops.sun_jnu_encoding = "MS950_HKSCS";
|
||||
}
|
||||
|
||||
hStdOutErr = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (hStdOutErr != INVALID_HANDLE_VALUE &&
|
||||
GetFileType(hStdOutErr) == FILE_TYPE_CHAR) {
|
||||
sprops.sun_stdout_encoding = getConsoleEncoding();
|
||||
}
|
||||
hStdOutErr = GetStdHandle(STD_ERROR_HANDLE);
|
||||
if (hStdOutErr != INVALID_HANDLE_VALUE &&
|
||||
GetFileType(hStdOutErr) == FILE_TYPE_CHAR) {
|
||||
if (sprops.sun_stdout_encoding != NULL)
|
||||
sprops.sun_stderr_encoding = sprops.sun_stdout_encoding;
|
||||
else
|
||||
sprops.sun_stderr_encoding = getConsoleEncoding();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,23 +238,25 @@ Java_sun_nio_ch_SocketDispatcher_writev0(JNIEnv *env, jclass clazz,
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_nio_ch_SocketDispatcher_close0(JNIEnv *env, jclass clazz,
|
||||
jobject fdo)
|
||||
Java_sun_nio_ch_SocketDispatcher_preClose0(JNIEnv *env, jclass clazz,
|
||||
jobject fdo)
|
||||
{
|
||||
jint fd = fdval(env, fdo);
|
||||
struct linger l;
|
||||
int len = sizeof(l);
|
||||
|
||||
if (fd != -1) {
|
||||
int result = 0;
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&l, &len) == 0) {
|
||||
if (l.l_onoff == 0) {
|
||||
WSASendDisconnect(fd, NULL);
|
||||
}
|
||||
}
|
||||
result = closesocket(fd);
|
||||
if (result == SOCKET_ERROR) {
|
||||
JNU_ThrowIOExceptionWithLastError(env, "Socket close failed");
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&l, &len) == 0) {
|
||||
if (l.l_onoff == 0) {
|
||||
WSASendDisconnect(fd, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_nio_ch_SocketDispatcher_close0(JNIEnv *env, jclass clazz,
|
||||
jobject fdo)
|
||||
{
|
||||
jint fd = fdval(env, fdo);
|
||||
if (closesocket(fd) == SOCKET_ERROR) {
|
||||
JNU_ThrowIOExceptionWithLastError(env, "Socket close failed");
|
||||
}
|
||||
}
|
||||
|
@ -432,14 +432,14 @@ jdk_awt: $(call TestDirs, com/sun/awt java/awt sun/awt \
|
||||
javax/imageio javax/print sun/pisces)
|
||||
$(call RunOthervmBatch)
|
||||
|
||||
# Stable agentvm testruns (minus items from PROBLEM_LIST)
|
||||
# Stable othervm testruns (minus items from PROBLEM_LIST)
|
||||
JDK_ALL_TARGETS += jdk_beans1
|
||||
JDK_DEFAULT_TARGETS += jdk_beans1
|
||||
jdk_beans1: $(call TestDirs, \
|
||||
java/beans/beancontext java/beans/PropertyChangeSupport \
|
||||
java/beans/Introspector java/beans/Performance \
|
||||
java/beans/VetoableChangeSupport java/beans/Statement)
|
||||
$(call RunAgentvmBatch)
|
||||
$(call RunOthervmBatch)
|
||||
|
||||
# Stable othervm testruns (minus items from PROBLEM_LIST)
|
||||
# Using agentvm has serious problems with these tests
|
||||
|
@ -114,83 +114,10 @@
|
||||
|
||||
# jdk_awt
|
||||
|
||||
# None of the awt tests are using samevm, might not be worth the effort due
|
||||
# to the vm overhead not being enough to make a difference.
|
||||
# In general, the awt tests are problematic with or without samevm, and there
|
||||
# are issues with using a Xvfb display.
|
||||
|
||||
# Fails on solaris sparc, timedout? in othervm mode
|
||||
java/awt/event/MouseEvent/AcceptExtraButton/AcceptExtraButton.java generic-all
|
||||
|
||||
# Causes hang in samevm mode??? Solaris 11 i586
|
||||
java/awt/FullScreen/SetFSWindow/FSFrame.java generic-all
|
||||
|
||||
# Fails on solaris 11 i586, -client, in othervm mode not sure why
|
||||
java/awt/Component/PrintAllXcheckJNI/PrintAllXcheckJNI.java generic-all
|
||||
java/awt/Focus/CloseDialogActivateOwnerTest/CloseDialogActivateOwnerTest.java generic-all
|
||||
java/awt/FontClass/FontAccess.java generic-all
|
||||
java/awt/Mixing/HWDisappear.java generic-all
|
||||
java/awt/Mixing/MixingInHwPanel.java generic-all
|
||||
java/awt/Mouse/MaximizedFrameTest/MaximizedFrameTest.html generic-all
|
||||
java/awt/Robot/AcceptExtraMouseButtons/AcceptExtraMouseButtons.java generic-all
|
||||
java/awt/Toolkit/SecurityTest/SecurityTest2.java generic-all
|
||||
java/awt/image/mlib/MlibOpsTest.java generic-all
|
||||
|
||||
# Fails on windows, othervm mode, various errors
|
||||
java/awt/Focus/NonFocusableWindowTest/NonfocusableOwnerTest.java generic-all
|
||||
java/awt/Focus/OwnedWindowFocusIMECrashTest/OwnedWindowFocusIMECrashTest.java generic-all
|
||||
java/awt/FullScreen/NoResizeEventOnDMChangeTest/NoResizeEventOnDMChangeTest.java generic-all
|
||||
java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Standard.java generic-all
|
||||
java/awt/event/KeyEvent/KeyTyped/CtrlASCII.html generic-all
|
||||
java/awt/font/Threads/FontThread.java generic-all
|
||||
java/awt/print/PrinterJob/PrtException.java generic-all
|
||||
|
||||
# Fails with windows X64, othervm, -server
|
||||
com/sun/awt/Translucency/WindowOpacity.java generic-all
|
||||
java/awt/EventDispatchThread/HandleExceptionOnEDT/HandleExceptionOnEDT.java generic-all
|
||||
java/awt/EventDispatchThread/LoopRobustness/LoopRobustness.html generic-all
|
||||
java/awt/Focus/AppletInitialFocusTest/AppletInitialFocusTest1.html generic-all
|
||||
java/awt/Focus/FocusEmbeddedFrameTest/FocusEmbeddedFrameTest.java generic-all
|
||||
java/awt/Frame/LayoutOnMaximizeTest/LayoutOnMaximizeTest.java generic-all
|
||||
java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java generic-all
|
||||
java/awt/Mixing/MixingOnShrinkingHWButton.java generic-all
|
||||
java/awt/Mouse/MouseModifiersUnitTest/ExtraButtonDrag.java generic-all
|
||||
|
||||
############################################################################
|
||||
|
||||
# jdk_beans
|
||||
|
||||
# A large set of the beans tests set the security manager, which would seem
|
||||
# to indicate that a large number of them should be "othervm", yet are all
|
||||
# very small tests and could greatly benefit from a samevm test run.
|
||||
# So a large batch of beans tests are currently run with othervm mode.
|
||||
|
||||
# Filed 6986807
|
||||
java/beans/Introspector/TestTypeResolver.java generic-all
|
||||
|
||||
# Filed 6986813
|
||||
java/beans/Introspector/memory/Test4508780.java generic-all
|
||||
|
||||
# Linux, some kind of problems with X11 display
|
||||
java/beans/PropertyChangeSupport/Test4682386.java generic-all
|
||||
java/beans/PropertyChangeSupport/TestSynchronization.java generic-all
|
||||
java/beans/Statement/Test4653179.java generic-all
|
||||
|
||||
# Runs REALLY slow on Solaris sparc for some reason, both -client and -server
|
||||
java/beans/XMLEncoder/Test4625418.java solaris-sparc
|
||||
|
||||
# Problems with samevm and setting security manager (speculation partially)
|
||||
java/beans/Introspector/4168475/Test4168475.java generic-all
|
||||
java/beans/Introspector/4520754/Test4520754.java generic-all
|
||||
java/beans/Introspector/6380849/TestBeanInfo.java generic-all
|
||||
java/beans/Introspector/Test4144543.java generic-all
|
||||
|
||||
# Failed to call method solaris-sparc???
|
||||
java/beans/EventHandler/Test6788531.java generic-all
|
||||
|
||||
# Jar or class not found???
|
||||
java/beans/XMLEncoder/6329581/Test6329581.java generic-all
|
||||
|
||||
############################################################################
|
||||
|
||||
# jdk_lang
|
||||
@ -211,6 +138,12 @@ java/lang/management/MemoryMXBean/CollectionUsageThreshold.java generic-all
|
||||
|
||||
# jdk_management
|
||||
|
||||
# 6959636
|
||||
javax/management/loading/LibraryLoader/LibraryLoaderTest.java windows-all
|
||||
|
||||
# 7144846
|
||||
javax/management/remote/mandatory/connection/ReconnectTest.java generic-all
|
||||
|
||||
# 7073626
|
||||
sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh windows-all
|
||||
sun/management/jmxremote/bootstrap/RmiSslBootstrapTest.sh windows-all
|
||||
@ -229,72 +162,6 @@ demo/jvmti/compiledMethodLoad/CompiledMethodLoadTest.java generic-all
|
||||
# Need to be marked othervm, or changed to be samevm safe
|
||||
com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java generic-all
|
||||
|
||||
# Need to be marked othervm, or changed to be samevm safe
|
||||
com/sun/org/apache/xml/internal/security/transforms/ClassLoaderTest.java generic-all
|
||||
|
||||
# Solaris sparc and others, exception in initializer
|
||||
javax/imageio/CachePremissionsTest/CachePermissionsTest.java generic-all
|
||||
|
||||
# Leaves file rgba_* open, fails with windows samevm
|
||||
javax/imageio/plugins/png/PngOutputTypeTest.java generic-all
|
||||
|
||||
# Suspect test.png file is left open, windows samevm problems
|
||||
javax/imageio/plugins/png/ITXtTest.java generic-all
|
||||
|
||||
# Solaris sparc and others, failed to compile testcase
|
||||
javax/imageio/metadata/DOML3Node.java generic-all
|
||||
|
||||
# One of these tests is leaving file IMGP1001.JPG open, windows samevm
|
||||
javax/imageio/plugins/jpeg/ConcurrentReadingTest.java generic-all
|
||||
javax/imageio/plugins/jpeg/ReadingInterruptionTest.java generic-all
|
||||
|
||||
# One of these files is missing a close on writer_* files, windows samevm
|
||||
javax/imageio/plugins/jpeg/ConcurrentWritingTest.java generic-all
|
||||
javax/imageio/plugins/jpeg/WritingInterruptionTest.java generic-all
|
||||
|
||||
# Leaving file test.jpg open, windows samevm
|
||||
javax/imageio/plugins/jpeg/ReadAsGrayTest.java generic-all
|
||||
|
||||
# Missing close on file wbmp*, windows samevm
|
||||
javax/imageio/plugins/wbmp/CanDecodeTest.java generic-all
|
||||
|
||||
# Failures on OpenSolaris, cannot read input files? samevm issues?
|
||||
javax/imageio/metadata/BooleanAttributes.java generic-all
|
||||
javax/imageio/plugins/bmp/BMPSubsamplingTest.java generic-all
|
||||
javax/imageio/plugins/bmp/TopDownTest.java generic-all
|
||||
javax/imageio/plugins/gif/EncodeSubImageTest.java generic-all
|
||||
javax/imageio/plugins/gif/GifTransparencyTest.java generic-all
|
||||
javax/imageio/plugins/png/GrayPngTest.java generic-all
|
||||
javax/imageio/plugins/png/ItxtUtf8Test.java generic-all
|
||||
javax/imageio/plugins/png/MergeStdCommentTest.java generic-all
|
||||
javax/imageio/plugins/png/ShortHistogramTest.java generic-all
|
||||
javax/imageio/plugins/shared/BitDepth.java generic-all
|
||||
|
||||
# Exclude all javax/print tests, even if they passed, they may need samevm work
|
||||
|
||||
# Times out on solaris-sparc, sparcv9, x64 -server, some on i586 -client
|
||||
javax/print/attribute/autosense/PrintAutoSenseData.java generic-all
|
||||
javax/print/attribute/Chroma.java generic-all
|
||||
javax/print/attribute/CollateAttr.java generic-all
|
||||
javax/print/attribute/PSCopiesFlavorTest.java generic-all
|
||||
javax/print/LookupServices.java generic-all
|
||||
javax/print/TestRaceCond.java generic-all
|
||||
|
||||
# These tests really require a printer (might all be windows only tests?)
|
||||
javax/print/CheckDupFlavor.java generic-all
|
||||
javax/print/PrintSE/PrintSE.sh generic-all
|
||||
javax/print/attribute/ChromaticityValues.java generic-all
|
||||
javax/print/attribute/GetCopiesSupported.java generic-all
|
||||
javax/print/attribute/SidesPageRangesTest.java generic-all
|
||||
javax/print/attribute/SupportedPrintableAreas.java generic-all
|
||||
javax/print/attribute/AttributeTest.java generic-all
|
||||
|
||||
# Only print test left, excluding just because all print tests have been
|
||||
javax/print/attribute/MediaMappingsTest.java generic-all
|
||||
|
||||
# Filed 7058852
|
||||
javax/sound/sampled/FileWriter/AlawEncoderSync.java generic-all
|
||||
|
||||
############################################################################
|
||||
|
||||
# jdk_net
|
||||
@ -317,6 +184,7 @@ java/net/InetAddress/CheckJNI.java linux-all
|
||||
# failing on vista 32/64 on nightly
|
||||
# 7102702
|
||||
java/net/PortUnreachableException/OneExceptionOnly.java windows-all
|
||||
|
||||
############################################################################
|
||||
|
||||
# jdk_io
|
||||
@ -354,6 +222,12 @@ java/rmi/registry/readTest/readTest.sh windows-all
|
||||
|
||||
# jdk_security
|
||||
|
||||
# 7145024
|
||||
sun/security/ssl/com/sun/net/ssl/internal/ssl/GenSSLConfigs/main.java solaris-all
|
||||
|
||||
# 7147060
|
||||
com/sun/org/apache/xml/internal/security/transforms/ClassLoaderTest.java generic-all
|
||||
|
||||
# Failing on Solaris i586, 3/9/2010, not a -samevm issue (jdk_security3)
|
||||
sun/security/pkcs11/Secmod/AddPrivateKey.java solaris-i586
|
||||
sun/security/pkcs11/ec/ReadCertificates.java solaris-i586
|
||||
@ -409,21 +283,16 @@ sun/security/tools/keytool/standard.sh solaris-all
|
||||
|
||||
############################################################################
|
||||
|
||||
# jdk_swing (not using samevm)
|
||||
# jdk_sound
|
||||
|
||||
# Fails on solaris 11 i586, with othervm
|
||||
javax/swing/JFileChooser/6570445/bug6570445.java generic-all
|
||||
javax/swing/JFileChooser/6738668/bug6738668.java generic-all
|
||||
javax/swing/JPopupMenu/6675802/bug6675802.java generic-all
|
||||
javax/swing/system/6799345/TestShutdown.java generic-all
|
||||
############################################################################
|
||||
|
||||
# jdk_swing
|
||||
|
||||
############################################################################
|
||||
|
||||
# jdk_text
|
||||
|
||||
# Linux x64 occasional errors, no details
|
||||
java/text/Bidi/Bug6665028.java linux-x64
|
||||
|
||||
############################################################################
|
||||
|
||||
# jdk_tools
|
||||
@ -452,7 +321,7 @@ sun/tools/jconsole/ResourceCheckTest.sh generic-all
|
||||
# 7132203
|
||||
sun/jvmstat/monitor/MonitoredVm/CR6672135.java generic-all
|
||||
|
||||
# Tests take too long
|
||||
# Tests take too long, see 7143279
|
||||
tools/pack200/CommandLineTests.java generic-all
|
||||
tools/pack200/Pack200Test.java generic-all
|
||||
|
||||
|
266
jdk/test/java/lang/Math/ExactArithTests.java
Normal file
266
jdk/test/java/lang/Math/ExactArithTests.java
Normal file
@ -0,0 +1,266 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 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.
|
||||
*/
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
* @test Test for Math.*Exact integer and long methods.
|
||||
* @bug 6708398
|
||||
* @summary Basic tests for Math exact arithmetic operations.
|
||||
*
|
||||
* @author Roger Riggs
|
||||
*/
|
||||
public class ExactArithTests {
|
||||
|
||||
/**
|
||||
* The count of test errors.
|
||||
*/
|
||||
private static int errors = 0;
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
testIntegerExact();
|
||||
testLongExact();
|
||||
|
||||
if (errors > 0) {
|
||||
throw new RuntimeException(errors + " errors found in ExactArithTests.");
|
||||
}
|
||||
}
|
||||
|
||||
static void fail(String message) {
|
||||
errors++;
|
||||
System.err.println(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Math.addExact, multiplyExact, subtractExact, toIntValue methods
|
||||
* with {@code int} arguments.
|
||||
*/
|
||||
static void testIntegerExact() {
|
||||
testIntegerExact(0, 0);
|
||||
testIntegerExact(1, 1);
|
||||
testIntegerExact(1, -1);
|
||||
testIntegerExact(-1, 1);
|
||||
testIntegerExact(1000, 2000);
|
||||
|
||||
testIntegerExact(Integer.MIN_VALUE, Integer.MIN_VALUE);
|
||||
testIntegerExact(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
testIntegerExact(Integer.MIN_VALUE, 1);
|
||||
testIntegerExact(Integer.MAX_VALUE, 1);
|
||||
testIntegerExact(Integer.MIN_VALUE, 2);
|
||||
testIntegerExact(Integer.MAX_VALUE, 2);
|
||||
testIntegerExact(Integer.MIN_VALUE, -1);
|
||||
testIntegerExact(Integer.MAX_VALUE, -1);
|
||||
testIntegerExact(Integer.MIN_VALUE, -2);
|
||||
testIntegerExact(Integer.MAX_VALUE, -2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exact arithmetic by comparing with the same operations using long
|
||||
* and checking that the result is the same as the integer truncation.
|
||||
* Errors are reported with {@link fail}.
|
||||
*
|
||||
* @param x first parameter
|
||||
* @param y second parameter
|
||||
*/
|
||||
static void testIntegerExact(int x, int y) {
|
||||
try {
|
||||
// Test addExact
|
||||
int sum = Math.addExact(x, y);
|
||||
long sum2 = (long) x + (long) y;
|
||||
if ((int) sum2 != sum2) {
|
||||
fail("FAIL: int Math.addExact(" + x + " + " + y + ") = " + sum + "; expected Arithmetic exception");
|
||||
} else if (sum != sum2) {
|
||||
fail("FAIL: long Math.addExact(" + x + " + " + y + ") = " + sum + "; expected: " + sum2);
|
||||
}
|
||||
} catch (ArithmeticException ex) {
|
||||
long sum2 = (long) x + (long) y;
|
||||
if ((int) sum2 == sum2) {
|
||||
fail("FAIL: int Math.addExact(" + x + " + " + y + ")" + "; Unexpected exception: " + ex);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Test subtractExact
|
||||
int diff = Math.subtractExact(x, y);
|
||||
long diff2 = (long) x - (long) y;
|
||||
if ((int) diff2 != diff2) {
|
||||
fail("FAIL: int Math.subtractExact(" + x + " - " + y + ") = " + diff + "; expected: " + diff2);
|
||||
}
|
||||
|
||||
} catch (ArithmeticException ex) {
|
||||
long diff2 = (long) x - (long) y;
|
||||
if ((int) diff2 == diff2) {
|
||||
fail("FAIL: int Math.subtractExact(" + x + " - " + y + ")" + "; Unexpected exception: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Test multiplyExact
|
||||
int product = Math.multiplyExact(x, y);
|
||||
long m2 = (long) x * (long) y;
|
||||
if ((int) m2 != m2) {
|
||||
fail("FAIL: int Math.multiplyExact(" + x + " * " + y + ") = " + product + "; expected: " + m2);
|
||||
}
|
||||
} catch (ArithmeticException ex) {
|
||||
long m2 = (long) x * (long) y;
|
||||
if ((int) m2 == m2) {
|
||||
fail("FAIL: int Math.multiplyExact(" + x + " * " + y + ")" + "; Unexpected exception: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Math.addExact, multiplyExact, subtractExact, toIntExact methods
|
||||
* with {@code long} arguments.
|
||||
*/
|
||||
static void testLongExact() {
|
||||
testLongExactTwice(0, 0);
|
||||
testLongExactTwice(1, 1);
|
||||
testLongExactTwice(1, -1);
|
||||
testLongExactTwice(1000, 2000);
|
||||
|
||||
testLongExactTwice(Long.MIN_VALUE, Long.MIN_VALUE);
|
||||
testLongExactTwice(Long.MAX_VALUE, Long.MAX_VALUE);
|
||||
testLongExactTwice(Long.MIN_VALUE, 1);
|
||||
testLongExactTwice(Long.MAX_VALUE, 1);
|
||||
testLongExactTwice(Long.MIN_VALUE, 2);
|
||||
testLongExactTwice(Long.MAX_VALUE, 2);
|
||||
testLongExactTwice(Long.MIN_VALUE, -1);
|
||||
testLongExactTwice(Long.MAX_VALUE, -1);
|
||||
testLongExactTwice(Long.MIN_VALUE, -2);
|
||||
testLongExactTwice(Long.MAX_VALUE, -2);
|
||||
testLongExactTwice(Long.MIN_VALUE/2, 2);
|
||||
testLongExactTwice(Long.MAX_VALUE, 2);
|
||||
testLongExactTwice(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
testLongExactTwice(Integer.MAX_VALUE, -Integer.MAX_VALUE);
|
||||
testLongExactTwice(Integer.MAX_VALUE+1, Integer.MAX_VALUE+1);
|
||||
testLongExactTwice(Integer.MAX_VALUE+1, -Integer.MAX_VALUE+1);
|
||||
testLongExactTwice(Integer.MIN_VALUE-1, Integer.MIN_VALUE-1);
|
||||
testLongExactTwice(Integer.MIN_VALUE-1, -Integer.MIN_VALUE-1);
|
||||
testLongExactTwice(Integer.MIN_VALUE/2, 2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test each of the exact operations with the arguments and
|
||||
* with the arguments reversed.
|
||||
* @param x
|
||||
* @param y
|
||||
*/
|
||||
static void testLongExactTwice(long x, long y) {
|
||||
testLongExact(x, y);
|
||||
testLongExact(y, x);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test long exact arithmetic by comparing with the same operations using BigInteger
|
||||
* and checking that the result is the same as the long truncation.
|
||||
* Errors are reported with {@link fail}.
|
||||
*
|
||||
* @param x first parameter
|
||||
* @param y second parameter
|
||||
*/
|
||||
static void testLongExact(long x, long y) {
|
||||
BigInteger resultBig = null;
|
||||
final BigInteger xBig = BigInteger.valueOf(x);
|
||||
final BigInteger yBig = BigInteger.valueOf(y);
|
||||
try {
|
||||
// Test addExact
|
||||
resultBig = xBig.add(yBig);
|
||||
long sum = Math.addExact(x, y);
|
||||
checkResult("long Math.addExact", x, y, sum, resultBig);
|
||||
} catch (ArithmeticException ex) {
|
||||
if (inLongRange(resultBig)) {
|
||||
fail("FAIL: long Math.addExact(" + x + " + " + y + "); Unexpected exception: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Test subtractExact
|
||||
resultBig = xBig.subtract(yBig);
|
||||
long diff = Math.subtractExact(x, y);
|
||||
checkResult("long Math.subtractExact", x, y, diff, resultBig);
|
||||
} catch (ArithmeticException ex) {
|
||||
if (inLongRange(resultBig)) {
|
||||
fail("FAIL: long Math.subtractExact(" + x + " - " + y + ")" + "; Unexpected exception: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Test multiplyExact
|
||||
resultBig = xBig.multiply(yBig);
|
||||
long product = Math.multiplyExact(x, y);
|
||||
checkResult("long Math.multiplyExact", x, y, product, resultBig);
|
||||
} catch (ArithmeticException ex) {
|
||||
if (inLongRange(resultBig)) {
|
||||
fail("FAIL: long Math.multiplyExact(" + x + " * " + y + ")" + "; Unexpected exception: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Test toIntExact
|
||||
int value = Math.toIntExact(x);
|
||||
if ((long)value != x) {
|
||||
fail("FAIL: " + "long Math.toIntExact" + "(" + x + ") = " + value + "; expected an arithmetic exception: ");
|
||||
}
|
||||
} catch (ArithmeticException ex) {
|
||||
if (resultBig.bitLength() <= 32) {
|
||||
fail("FAIL: long Math.toIntExact(" + x + ")" + "; Unexpected exception: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the expected and actual results.
|
||||
* @param message message for the error
|
||||
* @param x first argument
|
||||
* @param y second argument
|
||||
* @param result actual result value
|
||||
* @param expected expected result value
|
||||
*/
|
||||
static void checkResult(String message, long x, long y, long result, BigInteger expected) {
|
||||
BigInteger resultBig = BigInteger.valueOf(result);
|
||||
if (!inLongRange(expected)) {
|
||||
fail("FAIL: " + message + "(" + x + ", " + y + ") = " + result + "; expected an arithmetic exception: ");
|
||||
} else if (!resultBig.equals(expected)) {
|
||||
fail("FAIL: " + message + "(" + x + ", " + y + ") = " + result + "; expected " + expected);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the value fits in 64 bits (a long).
|
||||
* @param value
|
||||
* @return true if the value fits in 64 bits (including the sign).
|
||||
*/
|
||||
static boolean inLongRange(BigInteger value) {
|
||||
return value.bitLength() <= 63;
|
||||
}
|
||||
}
|
266
jdk/test/java/lang/StrictMath/ExactArithTests.java
Normal file
266
jdk/test/java/lang/StrictMath/ExactArithTests.java
Normal file
@ -0,0 +1,266 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 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.
|
||||
*/
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
* @test Test for StrictMath.*Exact integer and long methods.
|
||||
* @bug 6708398
|
||||
* @summary Basic tests for StrictMath exact arithmetic operations.
|
||||
*
|
||||
* @author Roger Riggs
|
||||
*/
|
||||
public class ExactArithTests {
|
||||
|
||||
/**
|
||||
* The count of test errors.
|
||||
*/
|
||||
private static int errors = 0;
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
testIntegerExact();
|
||||
testLongExact();
|
||||
|
||||
if (errors > 0) {
|
||||
throw new RuntimeException(errors + " errors found in ExactArithTests.");
|
||||
}
|
||||
}
|
||||
|
||||
static void fail(String message) {
|
||||
errors++;
|
||||
System.err.println(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test StrictMath.addExact, multiplyExact, subtractExact, toIntValue methods
|
||||
* with {@code int} arguments.
|
||||
*/
|
||||
static void testIntegerExact() {
|
||||
testIntegerExact(0, 0);
|
||||
testIntegerExact(1, 1);
|
||||
testIntegerExact(1, -1);
|
||||
testIntegerExact(-1, 1);
|
||||
testIntegerExact(1000, 2000);
|
||||
|
||||
testIntegerExact(Integer.MIN_VALUE, Integer.MIN_VALUE);
|
||||
testIntegerExact(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
testIntegerExact(Integer.MIN_VALUE, 1);
|
||||
testIntegerExact(Integer.MAX_VALUE, 1);
|
||||
testIntegerExact(Integer.MIN_VALUE, 2);
|
||||
testIntegerExact(Integer.MAX_VALUE, 2);
|
||||
testIntegerExact(Integer.MIN_VALUE, -1);
|
||||
testIntegerExact(Integer.MAX_VALUE, -1);
|
||||
testIntegerExact(Integer.MIN_VALUE, -2);
|
||||
testIntegerExact(Integer.MAX_VALUE, -2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exact arithmetic by comparing with the same operations using long
|
||||
* and checking that the result is the same as the integer truncation.
|
||||
* Errors are reported with {@link fail}.
|
||||
*
|
||||
* @param x first parameter
|
||||
* @param y second parameter
|
||||
*/
|
||||
static void testIntegerExact(int x, int y) {
|
||||
try {
|
||||
// Test addExact
|
||||
int sum = StrictMath.addExact(x, y);
|
||||
long sum2 = (long) x + (long) y;
|
||||
if ((int) sum2 != sum2) {
|
||||
fail("FAIL: int StrictMath.addExact(" + x + " + " + y + ") = " + sum + "; expected Arithmetic exception");
|
||||
} else if (sum != sum2) {
|
||||
fail("FAIL: long StrictMath.addExact(" + x + " + " + y + ") = " + sum + "; expected: " + sum2);
|
||||
}
|
||||
} catch (ArithmeticException ex) {
|
||||
long sum2 = (long) x + (long) y;
|
||||
if ((int) sum2 == sum2) {
|
||||
fail("FAIL: int StrictMath.addExact(" + x + " + " + y + ")" + "; Unexpected exception: " + ex);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Test subtractExact
|
||||
int diff = StrictMath.subtractExact(x, y);
|
||||
long diff2 = (long) x - (long) y;
|
||||
if ((int) diff2 != diff2) {
|
||||
fail("FAIL: int StrictMath.subtractExact(" + x + " - " + y + ") = " + diff + "; expected: " + diff2);
|
||||
}
|
||||
|
||||
} catch (ArithmeticException ex) {
|
||||
long diff2 = (long) x - (long) y;
|
||||
if ((int) diff2 == diff2) {
|
||||
fail("FAIL: int StrictMath.subtractExact(" + x + " - " + y + ")" + "; Unexpected exception: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Test multiplyExact
|
||||
int product = StrictMath.multiplyExact(x, y);
|
||||
long m2 = (long) x * (long) y;
|
||||
if ((int) m2 != m2) {
|
||||
fail("FAIL: int StrictMath.multiplyExact(" + x + " * " + y + ") = " + product + "; expected: " + m2);
|
||||
}
|
||||
} catch (ArithmeticException ex) {
|
||||
long m2 = (long) x * (long) y;
|
||||
if ((int) m2 == m2) {
|
||||
fail("FAIL: int StrictMath.multiplyExact(" + x + " * " + y + ")" + "; Unexpected exception: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test StrictMath.addExact, multiplyExact, subtractExact, toIntExact methods
|
||||
* with {@code long} arguments.
|
||||
*/
|
||||
static void testLongExact() {
|
||||
testLongExactTwice(0, 0);
|
||||
testLongExactTwice(1, 1);
|
||||
testLongExactTwice(1, -1);
|
||||
testLongExactTwice(1000, 2000);
|
||||
|
||||
testLongExactTwice(Long.MIN_VALUE, Long.MIN_VALUE);
|
||||
testLongExactTwice(Long.MAX_VALUE, Long.MAX_VALUE);
|
||||
testLongExactTwice(Long.MIN_VALUE, 1);
|
||||
testLongExactTwice(Long.MAX_VALUE, 1);
|
||||
testLongExactTwice(Long.MIN_VALUE, 2);
|
||||
testLongExactTwice(Long.MAX_VALUE, 2);
|
||||
testLongExactTwice(Long.MIN_VALUE, -1);
|
||||
testLongExactTwice(Long.MAX_VALUE, -1);
|
||||
testLongExactTwice(Long.MIN_VALUE, -2);
|
||||
testLongExactTwice(Long.MAX_VALUE, -2);
|
||||
testLongExactTwice(Long.MIN_VALUE/2, 2);
|
||||
testLongExactTwice(Long.MAX_VALUE, 2);
|
||||
testLongExactTwice(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
testLongExactTwice(Integer.MAX_VALUE, -Integer.MAX_VALUE);
|
||||
testLongExactTwice(Integer.MAX_VALUE+1, Integer.MAX_VALUE+1);
|
||||
testLongExactTwice(Integer.MAX_VALUE+1, -Integer.MAX_VALUE+1);
|
||||
testLongExactTwice(Integer.MIN_VALUE-1, Integer.MIN_VALUE-1);
|
||||
testLongExactTwice(Integer.MIN_VALUE-1, -Integer.MIN_VALUE-1);
|
||||
testLongExactTwice(Integer.MIN_VALUE/2, 2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test each of the exact operations with the arguments and
|
||||
* with the arguments reversed.
|
||||
* @param x
|
||||
* @param y
|
||||
*/
|
||||
static void testLongExactTwice(long x, long y) {
|
||||
testLongExact(x, y);
|
||||
testLongExact(y, x);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test long exact arithmetic by comparing with the same operations using BigInteger
|
||||
* and checking that the result is the same as the long truncation.
|
||||
* Errors are reported with {@link fail}.
|
||||
*
|
||||
* @param x first parameter
|
||||
* @param y second parameter
|
||||
*/
|
||||
static void testLongExact(long x, long y) {
|
||||
BigInteger resultBig = null;
|
||||
final BigInteger xBig = BigInteger.valueOf(x);
|
||||
final BigInteger yBig = BigInteger.valueOf(y);
|
||||
try {
|
||||
// Test addExact
|
||||
resultBig = xBig.add(yBig);
|
||||
long sum = StrictMath.addExact(x, y);
|
||||
checkResult("long StrictMath.addExact", x, y, sum, resultBig);
|
||||
} catch (ArithmeticException ex) {
|
||||
if (inLongRange(resultBig)) {
|
||||
fail("FAIL: long StrictMath.addExact(" + x + " + " + y + "); Unexpected exception: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Test subtractExact
|
||||
resultBig = xBig.subtract(yBig);
|
||||
long diff = StrictMath.subtractExact(x, y);
|
||||
checkResult("long StrictMath.subtractExact", x, y, diff, resultBig);
|
||||
} catch (ArithmeticException ex) {
|
||||
if (inLongRange(resultBig)) {
|
||||
fail("FAIL: long StrictMath.subtractExact(" + x + " - " + y + ")" + "; Unexpected exception: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Test multiplyExact
|
||||
resultBig = xBig.multiply(yBig);
|
||||
long product = StrictMath.multiplyExact(x, y);
|
||||
checkResult("long StrictMath.multiplyExact", x, y, product, resultBig);
|
||||
} catch (ArithmeticException ex) {
|
||||
if (inLongRange(resultBig)) {
|
||||
fail("FAIL: long StrictMath.multiplyExact(" + x + " * " + y + ")" + "; Unexpected exception: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Test toIntExact
|
||||
int value = StrictMath.toIntExact(x);
|
||||
if ((long)value != x) {
|
||||
fail("FAIL: " + "long StrictMath.toIntExact" + "(" + x + ") = " + value + "; expected an arithmetic exception: ");
|
||||
}
|
||||
} catch (ArithmeticException ex) {
|
||||
if (resultBig.bitLength() <= 32) {
|
||||
fail("FAIL: long StrictMath.toIntExact(" + x + ")" + "; Unexpected exception: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the expected and actual results.
|
||||
* @param message message for the error
|
||||
* @param x first argument
|
||||
* @param y second argument
|
||||
* @param result actual result value
|
||||
* @param expected expected result value
|
||||
*/
|
||||
static void checkResult(String message, long x, long y, long result, BigInteger expected) {
|
||||
BigInteger resultBig = BigInteger.valueOf(result);
|
||||
if (!inLongRange(expected)) {
|
||||
fail("FAIL: " + message + "(" + x + ", " + y + ") = " + result + "; expected an arithmetic exception: ");
|
||||
} else if (!resultBig.equals(expected)) {
|
||||
fail("FAIL: " + message + "(" + x + ", " + y + ") = " + result + "; expected " + expected);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the value fits in 64 bits (a long).
|
||||
* @param value
|
||||
* @return true if the value fits in 64 bits (including the sign).
|
||||
*/
|
||||
static boolean inLongRange(BigInteger value) {
|
||||
return value.bitLength() <= 63;
|
||||
}
|
||||
}
|
58
jdk/test/sun/security/krb5/ktab/FileKeyTab.java
Normal file
58
jdk/test/sun/security/krb5/ktab/FileKeyTab.java
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 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 7144530
|
||||
* @summary KeyTab.getInstance(String) no longer handles keyTabNames with "file:" prefix
|
||||
*/
|
||||
import java.io.File;
|
||||
import sun.security.krb5.PrincipalName;
|
||||
import sun.security.krb5.internal.ktab.KeyTab;
|
||||
|
||||
public class FileKeyTab {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String name = "ktab";
|
||||
KeyTab kt = KeyTab.create(name);
|
||||
kt.addEntry(new PrincipalName("a@A"), "x".toCharArray(), 1, true);
|
||||
kt.save();
|
||||
check(name);
|
||||
check("FILE:" + name);
|
||||
|
||||
name = new File(name).getAbsolutePath().toString();
|
||||
|
||||
check(name);
|
||||
check("FILE:" + name);
|
||||
|
||||
// The bug reporter uses this style, should only work for
|
||||
// absolute path
|
||||
check("FILE:/" + name);
|
||||
}
|
||||
|
||||
static void check(String file) throws Exception {
|
||||
System.out.println("Checking for " + file + "...");
|
||||
KeyTab kt2 = KeyTab.getInstance(file);
|
||||
if (kt2.isMissing()) {
|
||||
throw new Exception("FILE:ktab cannot be loaded");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user