Merge
This commit is contained in:
commit
da6f620059
src
hotspot/share/classfile
java.base/share/classes/java/math
java.rmi/share/classes/sun/rmi
test
hotspot/jtreg/runtime/appcds
jdk/java
math/BigDecimal
rmi/registry/nonLocalRegistry
@ -5975,9 +5975,9 @@ void ClassFileParser::parse_stream(const ClassFileStream* const stream,
|
||||
_minor_version = stream->get_u2_fast();
|
||||
_major_version = stream->get_u2_fast();
|
||||
|
||||
if (DumpSharedSpaces && _major_version < JAVA_1_5_VERSION) {
|
||||
if (DumpSharedSpaces && _major_version < JAVA_6_VERSION) {
|
||||
ResourceMark rm;
|
||||
warning("Pre JDK 1.5 class not supported by CDS: %u.%u %s",
|
||||
warning("Pre JDK 6 class not supported by CDS: %u.%u %s",
|
||||
_major_version, _minor_version, _class_name->as_C_string());
|
||||
Exceptions::fthrow(
|
||||
THREAD_AND_LOCATION,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2019, 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
|
||||
@ -3414,9 +3414,32 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
|
||||
*/
|
||||
@Override
|
||||
public long longValue(){
|
||||
return (intCompact != INFLATED && scale == 0) ?
|
||||
intCompact:
|
||||
toBigInteger().longValue();
|
||||
if (intCompact != INFLATED && scale == 0) {
|
||||
return intCompact;
|
||||
} else {
|
||||
// Fastpath zero and small values
|
||||
if (this.signum() == 0 || fractionOnly() ||
|
||||
// Fastpath very large-scale values that will result
|
||||
// in a truncated value of zero. If the scale is -64
|
||||
// or less, there are at least 64 powers of 10 in the
|
||||
// value of the numerical result. Since 10 = 2*5, in
|
||||
// that case there would also be 64 powers of 2 in the
|
||||
// result, meaning all 64 bits of a long will be zero.
|
||||
scale <= -64) {
|
||||
return 0;
|
||||
} else {
|
||||
return toBigInteger().longValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if a nonzero BigDecimal has an absolute value less
|
||||
* than one; i.e. only has fraction digits.
|
||||
*/
|
||||
private boolean fractionOnly() {
|
||||
assert this.signum() != 0;
|
||||
return (this.precision() - this.scale) <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3434,15 +3457,20 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
|
||||
public long longValueExact() {
|
||||
if (intCompact != INFLATED && scale == 0)
|
||||
return intCompact;
|
||||
|
||||
// Fastpath zero
|
||||
if (this.signum() == 0)
|
||||
return 0;
|
||||
|
||||
// Fastpath numbers less than 1.0 (the latter can be very slow
|
||||
// to round if very small)
|
||||
if (fractionOnly())
|
||||
throw new ArithmeticException("Rounding necessary");
|
||||
|
||||
// If more than 19 digits in integer part it cannot possibly fit
|
||||
if ((precision() - scale) > 19) // [OK for negative scale too]
|
||||
throw new java.lang.ArithmeticException("Overflow");
|
||||
// Fastpath zero and < 1.0 numbers (the latter can be very slow
|
||||
// to round if very small)
|
||||
if (this.signum() == 0)
|
||||
return 0;
|
||||
if ((this.precision() - this.scale) <= 0)
|
||||
throw new ArithmeticException("Rounding necessary");
|
||||
|
||||
// round to an integer, with Exception if decimal part non-0
|
||||
BigDecimal num = this.setScale(0, ROUND_UNNECESSARY);
|
||||
if (num.precision() >= 19) // need to check carefully
|
||||
@ -3486,7 +3514,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
|
||||
public int intValue() {
|
||||
return (intCompact != INFLATED && scale == 0) ?
|
||||
(int)intCompact :
|
||||
toBigInteger().intValue();
|
||||
(int)longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2019, 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
|
||||
@ -58,8 +58,24 @@ public final class RegistryImpl_Skel
|
||||
|
||||
public void dispatch(java.rmi.Remote obj, java.rmi.server.RemoteCall call, int opnum, long hash)
|
||||
throws java.lang.Exception {
|
||||
if (hash != interfaceHash)
|
||||
throw new java.rmi.server.SkeletonMismatchException("interface hash mismatch");
|
||||
if (opnum < 0) {
|
||||
if (hash == 7583982177005850366L) {
|
||||
opnum = 0;
|
||||
} else if (hash == 2571371476350237748L) {
|
||||
opnum = 1;
|
||||
} else if (hash == -7538657168040752697L) {
|
||||
opnum = 2;
|
||||
} else if (hash == -8381844669958460146L) {
|
||||
opnum = 3;
|
||||
} else if (hash == 7305022919901907578L) {
|
||||
opnum = 4;
|
||||
} else {
|
||||
throw new java.rmi.UnmarshalException("invalid method hash");
|
||||
}
|
||||
} else {
|
||||
if (hash != interfaceHash)
|
||||
throw new java.rmi.server.SkeletonMismatchException("interface hash mismatch");
|
||||
}
|
||||
|
||||
sun.rmi.registry.RegistryImpl server = (sun.rmi.registry.RegistryImpl) obj;
|
||||
switch (opnum) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2019, 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,6 +40,7 @@ import java.rmi.ServerError;
|
||||
import java.rmi.ServerException;
|
||||
import java.rmi.UnmarshalException;
|
||||
import java.rmi.server.ExportException;
|
||||
import java.rmi.server.Operation;
|
||||
import java.rmi.server.RemoteCall;
|
||||
import java.rmi.server.RemoteRef;
|
||||
import java.rmi.server.RemoteStub;
|
||||
@ -292,15 +293,14 @@ public class UnicastServerRef extends UnicastRef
|
||||
throw new UnmarshalException("error unmarshalling call header",
|
||||
readEx);
|
||||
}
|
||||
if (num >= 0) {
|
||||
if (skel != null) {
|
||||
if (skel != null) {
|
||||
// If there is a skeleton, use it
|
||||
oldDispatch(obj, call, num);
|
||||
return;
|
||||
} else {
|
||||
throw new UnmarshalException(
|
||||
"skeleton class not found but required " +
|
||||
"for client version");
|
||||
}
|
||||
|
||||
} else if (num >= 0){
|
||||
throw new UnmarshalException(
|
||||
"skeleton class not found but required for client version");
|
||||
}
|
||||
try {
|
||||
op = in.readLong();
|
||||
@ -428,8 +428,8 @@ public class UnicastServerRef extends UnicastRef
|
||||
|
||||
/**
|
||||
* Handle server-side dispatch using the RMI 1.1 stub/skeleton
|
||||
* protocol, given a non-negative operation number that has
|
||||
* already been read from the call stream.
|
||||
* protocol, given a non-negative operation number or negative method hash
|
||||
* that has already been read from the call stream.
|
||||
* Exceptions are handled by the caller to be sent to the remote client.
|
||||
*
|
||||
* @param obj the target remote object for the call
|
||||
@ -461,7 +461,8 @@ public class UnicastServerRef extends UnicastRef
|
||||
}
|
||||
|
||||
// if calls are being logged, write out object id and operation
|
||||
logCall(obj, skel.getOperations()[op]);
|
||||
Operation[] operations = skel.getOperations();
|
||||
logCall(obj, op >= 0 && op < operations.length ? operations[op] : "op: " + op);
|
||||
unmarshalCustomCallData(in);
|
||||
// dispatch to skeleton for remote object
|
||||
skel.dispatch(obj, call, op, hash);
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary classes with major version < JDK_1.5 (48) should not be included in CDS
|
||||
* @summary classes with major version < JDK_6 (50) should not be included in CDS
|
||||
* @requires vm.cds
|
||||
* @library /test/lib
|
||||
* @modules java.base/jdk.internal.org.objectweb.asm
|
||||
@ -61,9 +61,9 @@ public class OldClassTest implements Opcodes {
|
||||
|
||||
String appClasses[] = TestCommon.list("Hello");
|
||||
|
||||
// CASE 1: pre-JDK 1.5 compiled classes should be excluded from the dump
|
||||
// CASE 1: pre-JDK 6 compiled classes should be excluded from the dump
|
||||
OutputAnalyzer output = TestCommon.dump(jar, appClasses);
|
||||
TestCommon.checkExecReturn(output, 0, true, "Pre JDK 1.5 class not supported by CDS");
|
||||
TestCommon.checkExecReturn(output, 0, true, "Pre JDK 6 class not supported by CDS");
|
||||
|
||||
TestCommon.run(
|
||||
"-cp", jar,
|
||||
@ -74,7 +74,7 @@ public class OldClassTest implements Opcodes {
|
||||
// the newer version of this class in a subsequent classpath element.
|
||||
String classpath = jar + File.pathSeparator + jarSrcFile.getPath();
|
||||
output = TestCommon.dump(classpath, appClasses);
|
||||
TestCommon.checkExecReturn(output, 0, true, "Pre JDK 1.5 class not supported by CDS");
|
||||
TestCommon.checkExecReturn(output, 0, true, "Pre JDK 6 class not supported by CDS");
|
||||
|
||||
TestCommon.run(
|
||||
"-cp", classpath,
|
||||
@ -127,8 +127,7 @@ java jdk.internal.org.objectweb.asm.util.ASMifier Hello.class
|
||||
MethodVisitor mv;
|
||||
AnnotationVisitor av0;
|
||||
|
||||
//WAS cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, "Hello", null, "java/lang/Object", null);
|
||||
cw.visit(V1_4, ACC_PUBLIC + ACC_SUPER, "Hello", null, "java/lang/Object", null);
|
||||
cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "Hello", null, "java/lang/Object", null);
|
||||
|
||||
{
|
||||
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
|
||||
|
120
test/jdk/java/math/BigDecimal/IntValueExactTests.java
Normal file
120
test/jdk/java/math/BigDecimal/IntValueExactTests.java
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 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 8211936
|
||||
* @summary Tests of BigDecimal.intValueExact
|
||||
*/
|
||||
import java.math.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import static java.util.Map.entry;
|
||||
|
||||
public class IntValueExactTests {
|
||||
public static void main(String... args) {
|
||||
int failures = 0;
|
||||
|
||||
failures += intValueExactSuccessful();
|
||||
failures += intValueExactExceptional();
|
||||
|
||||
if (failures > 0) {
|
||||
throw new RuntimeException("Incurred " + failures +
|
||||
" failures while testing intValueExact.");
|
||||
}
|
||||
}
|
||||
|
||||
private static int simpleIntValueExact(BigDecimal bd) {
|
||||
return bd.toBigIntegerExact().intValue();
|
||||
}
|
||||
|
||||
private static int intValueExactSuccessful() {
|
||||
int failures = 0;
|
||||
|
||||
// Strings used to create BigDecimal instances on which invoking
|
||||
// intValueExact() will succeed.
|
||||
Map<BigDecimal, Integer> successCases =
|
||||
Map.ofEntries(entry(new BigDecimal("2147483647"), Integer.MAX_VALUE), // 2^31 -1
|
||||
entry(new BigDecimal("2147483647.0"), Integer.MAX_VALUE),
|
||||
entry(new BigDecimal("2147483647.00"), Integer.MAX_VALUE),
|
||||
|
||||
entry(new BigDecimal("-2147483648"), Integer.MIN_VALUE), // -2^31
|
||||
entry(new BigDecimal("-2147483648.0"), Integer.MIN_VALUE),
|
||||
entry(new BigDecimal("-2147483648.00"),Integer.MIN_VALUE),
|
||||
|
||||
entry(new BigDecimal("1e0"), 1),
|
||||
entry(new BigDecimal(BigInteger.ONE, -9), 1_000_000_000),
|
||||
|
||||
entry(new BigDecimal("0e13"), 0), // Fast path zero
|
||||
entry(new BigDecimal("0e32"), 0),
|
||||
entry(new BigDecimal("0e512"), 0),
|
||||
|
||||
entry(new BigDecimal("10.000000000000000000000000000000000"), 10));
|
||||
|
||||
for (var testCase : successCases.entrySet()) {
|
||||
BigDecimal bd = testCase.getKey();
|
||||
int expected = testCase.getValue();
|
||||
try {
|
||||
int intValueExact = bd.intValueExact();
|
||||
if (expected != intValueExact ||
|
||||
intValueExact != simpleIntValueExact(bd)) {
|
||||
failures++;
|
||||
System.err.println("Unexpected intValueExact result " + intValueExact +
|
||||
" on " + bd);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
failures++;
|
||||
System.err.println("Error on " + bd + "\tException message:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
return failures;
|
||||
}
|
||||
|
||||
private static int intValueExactExceptional() {
|
||||
int failures = 0;
|
||||
List<BigDecimal> exceptionalCases =
|
||||
List.of(new BigDecimal("2147483648"), // Integer.MAX_VALUE + 1
|
||||
new BigDecimal("2147483648.0"),
|
||||
new BigDecimal("2147483648.00"),
|
||||
new BigDecimal("-2147483649"), // Integer.MIN_VALUE - 1
|
||||
new BigDecimal("-2147483649.1"),
|
||||
new BigDecimal("-2147483649.01"),
|
||||
|
||||
new BigDecimal("9999999999999999999999999999999"),
|
||||
new BigDecimal("10000000000000000000000000000000"),
|
||||
|
||||
new BigDecimal("0.99"),
|
||||
new BigDecimal("0.999999999999999999999"));
|
||||
|
||||
for (BigDecimal bd : exceptionalCases) {
|
||||
try {
|
||||
int intValueExact = bd.intValueExact();
|
||||
failures++;
|
||||
System.err.println("Unexpected non-exceptional intValueExact on " + bd);
|
||||
} catch (ArithmeticException e) {
|
||||
// Success;
|
||||
}
|
||||
}
|
||||
return failures;
|
||||
}
|
||||
}
|
241
test/jdk/java/math/BigDecimal/IntegralValueTests.java
Normal file
241
test/jdk/java/math/BigDecimal/IntegralValueTests.java
Normal file
@ -0,0 +1,241 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 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 8211936
|
||||
* @summary Tests of BigDecimal.intValue() and BigDecimal.longValue()
|
||||
*/
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
public class IntegralValueTests {
|
||||
public static void main(String... args) {
|
||||
int failures =
|
||||
integralValuesTest(INT_VALUES, true) +
|
||||
integralValuesTest(LONG_VALUES, false);
|
||||
if (failures != 0) {
|
||||
throw new RuntimeException
|
||||
("Incurred " + failures + " failures for {int,long}Value().");
|
||||
}
|
||||
}
|
||||
|
||||
private static final Map<BigDecimal, Number> INT_VALUES =
|
||||
Map.ofEntries(
|
||||
|
||||
// 2**31 - 1
|
||||
Map.entry(new BigDecimal("2147483647"), Integer.MAX_VALUE),
|
||||
Map.entry(new BigDecimal("2147483647.0"), Integer.MAX_VALUE),
|
||||
Map.entry(new BigDecimal("2147483647.00"), Integer.MAX_VALUE),
|
||||
|
||||
Map.entry(new BigDecimal("-2147483647"), -Integer.MAX_VALUE),
|
||||
Map.entry(new BigDecimal("-2147483647.0"), -Integer.MAX_VALUE),
|
||||
|
||||
// -2**31
|
||||
Map.entry(new BigDecimal("-2147483648"), Integer.MIN_VALUE),
|
||||
Map.entry(new BigDecimal("-2147483648.1"), Integer.MIN_VALUE),
|
||||
Map.entry(new BigDecimal("-2147483648.01"), Integer.MIN_VALUE),
|
||||
|
||||
// -2**31 + 1 truncation to 2**31 - 1
|
||||
Map.entry(new BigDecimal("-2147483649"), Integer.MAX_VALUE),
|
||||
|
||||
// 2**64 - 1 truncation to 1
|
||||
Map.entry(new BigDecimal("4294967295"), -1),
|
||||
|
||||
// 2**64 truncation to 0
|
||||
Map.entry(new BigDecimal("4294967296"), 0),
|
||||
|
||||
// Fast path truncation to 0
|
||||
Map.entry(new BigDecimal("1e32"), 0),
|
||||
|
||||
// Slow path truncation to -2**31
|
||||
Map.entry(new BigDecimal("1e31"), Integer.MIN_VALUE),
|
||||
|
||||
// Slow path
|
||||
Map.entry(new BigDecimal("1e0"), 1),
|
||||
|
||||
// Fast path round to 0
|
||||
Map.entry(new BigDecimal("9e-1"), 0),
|
||||
|
||||
// Some random values
|
||||
Map.entry(new BigDecimal("900e-1"), 90), // Increasing negative exponents
|
||||
Map.entry(new BigDecimal("900e-2"), 9),
|
||||
Map.entry(new BigDecimal("900e-3"), 0),
|
||||
|
||||
// Fast path round to 0
|
||||
Map.entry(new BigDecimal("123456789e-9"), 0),
|
||||
|
||||
// Slow path round to 1
|
||||
Map.entry(new BigDecimal("123456789e-8"), 1),
|
||||
|
||||
// Increasing positive exponents
|
||||
Map.entry(new BigDecimal("10000001e1"), 100000010),
|
||||
Map.entry(new BigDecimal("10000001e10"), -1315576832),
|
||||
Map.entry(new BigDecimal("10000001e100"), 0),
|
||||
Map.entry(new BigDecimal("10000001e1000"), 0),
|
||||
Map.entry(new BigDecimal("10000001e10000"), 0),
|
||||
Map.entry(new BigDecimal("10000001e100000"), 0),
|
||||
Map.entry(new BigDecimal("10000001e1000000"), 0),
|
||||
Map.entry(new BigDecimal("10000001e10000000"), 0),
|
||||
Map.entry(new BigDecimal("10000001e100000000"), 0),
|
||||
Map.entry(new BigDecimal("10000001e1000000000"), 0),
|
||||
|
||||
// Increasing negative exponents
|
||||
Map.entry(new BigDecimal("10000001e-1"), 1000000),
|
||||
Map.entry(new BigDecimal("10000001e-10"), 0),
|
||||
Map.entry(new BigDecimal("10000001e-100"), 0),
|
||||
Map.entry(new BigDecimal("10000001e-1000"), 0),
|
||||
Map.entry(new BigDecimal("10000001e-10000"), 0),
|
||||
Map.entry(new BigDecimal("10000001e-100000"), 0),
|
||||
Map.entry(new BigDecimal("10000001e-1000000"), 0),
|
||||
Map.entry(new BigDecimal("10000001e-10000000"), 0),
|
||||
Map.entry(new BigDecimal("10000001e-100000000"), 0),
|
||||
Map.entry(new BigDecimal("10000001e-1000000000"), 0),
|
||||
|
||||
// Currency calculation to 4 places
|
||||
Map.entry(new BigDecimal("12345.0001"), 12345),
|
||||
Map.entry(new BigDecimal("12345.9999"), 12345),
|
||||
Map.entry(new BigDecimal("-12345.0001"), -12345),
|
||||
Map.entry(new BigDecimal("-12345.9999"), -12345));
|
||||
|
||||
private static final Map<BigDecimal, Number> LONG_VALUES =
|
||||
Map.ofEntries(
|
||||
// 2**63 - 1
|
||||
Map.entry(new BigDecimal("9223372036854775807"), Long.MAX_VALUE),
|
||||
Map.entry(new BigDecimal("9223372036854775807.0"), Long.MAX_VALUE),
|
||||
Map.entry(new BigDecimal("9223372036854775807.00"), Long.MAX_VALUE),
|
||||
|
||||
// 2**63 truncation to -2**63
|
||||
Map.entry(new BigDecimal("-9223372036854775808"), Long.MIN_VALUE),
|
||||
Map.entry(new BigDecimal("-9223372036854775808.1"), Long.MIN_VALUE),
|
||||
Map.entry(new BigDecimal("-9223372036854775808.01"), Long.MIN_VALUE),
|
||||
|
||||
// -2**63 + 1 truncation to 2**63 - 1
|
||||
Map.entry(new BigDecimal("-9223372036854775809"), 9223372036854775807L),
|
||||
|
||||
// 2**64 - 1 truncation to -1
|
||||
Map.entry(new BigDecimal("18446744073709551615"), -1L),
|
||||
|
||||
// 2**64 truncation to 0
|
||||
Map.entry(new BigDecimal("18446744073709551616"), 0L),
|
||||
|
||||
// Slow path truncation to -2**63
|
||||
Map.entry(new BigDecimal("1e63"), -9223372036854775808L),
|
||||
Map.entry(new BigDecimal("-1e63"), -9223372036854775808L),
|
||||
// Fast path with larger magnitude scale
|
||||
Map.entry(new BigDecimal("1e64"), 0L),
|
||||
Map.entry(new BigDecimal("-1e64"), 0L),
|
||||
Map.entry(new BigDecimal("1e65"), 0L),
|
||||
Map.entry(new BigDecimal("-1e65"), 0L),
|
||||
|
||||
// Slow path
|
||||
Map.entry(new BigDecimal("1e0"), 1L),
|
||||
|
||||
// Fast path round to 0
|
||||
Map.entry(new BigDecimal("9e-1"), 0L),
|
||||
|
||||
// Some random values
|
||||
Map.entry(new BigDecimal("900e-1"), 90L), // Increasing negative exponents
|
||||
Map.entry(new BigDecimal("900e-2"), 9L),
|
||||
Map.entry(new BigDecimal("900e-3"), 0L),
|
||||
|
||||
// Fast path round to 0
|
||||
Map.entry(new BigDecimal("123456789e-9"), 0L),
|
||||
|
||||
// Slow path round to 1
|
||||
Map.entry(new BigDecimal("123456789e-8"), 1L),
|
||||
|
||||
// Increasing positive exponents
|
||||
Map.entry(new BigDecimal("10000001e1"), 100000010L),
|
||||
Map.entry(new BigDecimal("10000001e10"), 100000010000000000L),
|
||||
Map.entry(new BigDecimal("10000001e100"), 0L),
|
||||
Map.entry(new BigDecimal("10000001e1000"), 0L),
|
||||
Map.entry(new BigDecimal("10000001e10000"), 0L),
|
||||
Map.entry(new BigDecimal("10000001e100000"), 0L),
|
||||
Map.entry(new BigDecimal("10000001e1000000"), 0L),
|
||||
Map.entry(new BigDecimal("10000001e10000000"), 0L),
|
||||
Map.entry(new BigDecimal("10000001e100000000"), 0L),
|
||||
Map.entry(new BigDecimal("10000001e1000000000"), 0L),
|
||||
|
||||
// Increasing negative exponents
|
||||
Map.entry(new BigDecimal("10000001e-1"), 1000000L),
|
||||
Map.entry(new BigDecimal("10000001e-10"), 0L),
|
||||
Map.entry(new BigDecimal("10000001e-100"), 0L),
|
||||
Map.entry(new BigDecimal("10000001e-1000"), 0L),
|
||||
Map.entry(new BigDecimal("10000001e-10000"), 0L),
|
||||
Map.entry(new BigDecimal("10000001e-100000"), 0L),
|
||||
Map.entry(new BigDecimal("10000001e-1000000"), 0L),
|
||||
Map.entry(new BigDecimal("10000001e-10000000"), 0L),
|
||||
Map.entry(new BigDecimal("10000001e-100000000"), 0L),
|
||||
Map.entry(new BigDecimal("10000001e-1000000000"), 0L),
|
||||
|
||||
// Currency calculation to 4 places
|
||||
Map.entry(new BigDecimal("12345.0001"), 12345L),
|
||||
Map.entry(new BigDecimal("12345.9999"), 12345L),
|
||||
Map.entry(new BigDecimal("-12345.0001"), -12345L),
|
||||
Map.entry(new BigDecimal("-12345.9999"), -12345L));
|
||||
|
||||
private static int integralValuesTest(Map<BigDecimal, Number> v, boolean isInt) {
|
||||
System.err.format("Testing %s%n", isInt ? "Integer" : "Long");
|
||||
int failures = 0;
|
||||
for (var testCase : v.entrySet()) {
|
||||
BigDecimal bd = testCase.getKey();
|
||||
Number expected = testCase.getValue();
|
||||
try {
|
||||
if (isInt) {
|
||||
int intValue = bd.intValue();
|
||||
if (intValue != (int)expected) {
|
||||
failures += reportError(bd, expected, intValue, isInt);
|
||||
}
|
||||
} else {
|
||||
long longValue = bd.longValue();
|
||||
if (longValue != (long)expected) {
|
||||
failures += reportError(bd, expected, longValue, isInt);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
failures++;
|
||||
System.err.format("Unexpected exception %s for %s%n",
|
||||
e, bd.toString());
|
||||
}
|
||||
}
|
||||
return failures;
|
||||
}
|
||||
|
||||
private static int reportError(BigDecimal bd, Number expected, long longValue, boolean isInt) {
|
||||
System.err.format("For %s, scale=%d, expected %d, actual %d, simple %d%n",
|
||||
bd.toString(), bd.scale(),
|
||||
(isInt ? (Integer) expected : (Long) expected ),
|
||||
longValue,
|
||||
(isInt ? simpleIntValue(bd): simpleLongValue(bd) ));
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static long simpleLongValue(BigDecimal bd) {
|
||||
return bd.toBigInteger().longValue();
|
||||
}
|
||||
|
||||
private static int simpleIntValue(BigDecimal bd) {
|
||||
return bd.toBigInteger().intValue();
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2019, 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
|
||||
@ -23,65 +23,98 @@
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 6806261
|
||||
* @bug 6806261 8211936
|
||||
* @summary Tests of BigDecimal.longValueExact
|
||||
*/
|
||||
import java.math.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import static java.util.Map.entry;
|
||||
|
||||
public class LongValueExactTests {
|
||||
|
||||
private static int longValueExactTests() {
|
||||
public static void main(String... args) {
|
||||
int failures = 0;
|
||||
|
||||
String[] testStrings = {
|
||||
"9223372036854775807",
|
||||
"9223372036854775807.0",
|
||||
"9223372036854775807.00",
|
||||
"-9223372036854775808",
|
||||
"-9223372036854775808.0",
|
||||
"-9223372036854775808.00",
|
||||
};
|
||||
|
||||
for (String longValue : testStrings) {
|
||||
try {
|
||||
BigDecimal bd = new BigDecimal(longValue);
|
||||
long longValueExact = bd.longValueExact();
|
||||
} catch (Exception e) {
|
||||
failures++;
|
||||
}
|
||||
}
|
||||
|
||||
// The following Strings are supposed to make longValueExact throw
|
||||
// ArithmeticException.
|
||||
String[] testStrings2 = {
|
||||
"9223372036854775808",
|
||||
"9223372036854775808.0",
|
||||
"9223372036854775808.00",
|
||||
"-9223372036854775809",
|
||||
"-9223372036854775808.1",
|
||||
"-9223372036854775808.01",
|
||||
};
|
||||
|
||||
for (String bigValue : testStrings2) {
|
||||
try {
|
||||
BigDecimal bd = new BigDecimal(bigValue);
|
||||
long longValueExact = bd.longValueExact();
|
||||
failures++;
|
||||
} catch (ArithmeticException e) {
|
||||
// Success;
|
||||
}
|
||||
}
|
||||
return failures;
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
int failures = 0;
|
||||
|
||||
failures += longValueExactTests();
|
||||
failures += longValueExactSuccessful();
|
||||
failures += longValueExactExceptional();
|
||||
|
||||
if (failures > 0) {
|
||||
throw new RuntimeException("Incurred " + failures +
|
||||
" failures while testing longValueExact.");
|
||||
}
|
||||
}
|
||||
|
||||
private static long simpleLongValueExact(BigDecimal bd) {
|
||||
return bd.toBigIntegerExact().longValue();
|
||||
}
|
||||
|
||||
private static int longValueExactSuccessful() {
|
||||
int failures = 0;
|
||||
|
||||
// Strings used to create BigDecimal instances on which invoking
|
||||
// longValueExact() will succeed.
|
||||
Map<BigDecimal, Long> successCases =
|
||||
Map.ofEntries(entry(new BigDecimal("9223372036854775807"), Long.MAX_VALUE), // 2^63 -1
|
||||
entry(new BigDecimal("9223372036854775807.0"), Long.MAX_VALUE),
|
||||
entry(new BigDecimal("9223372036854775807.00"), Long.MAX_VALUE),
|
||||
|
||||
entry(new BigDecimal("-9223372036854775808"), Long.MIN_VALUE), // -2^63
|
||||
entry(new BigDecimal("-9223372036854775808.0"), Long.MIN_VALUE),
|
||||
entry(new BigDecimal("-9223372036854775808.00"),Long.MIN_VALUE),
|
||||
|
||||
entry(new BigDecimal("1e0"), 1L),
|
||||
entry(new BigDecimal(BigInteger.ONE, -18), 1_000_000_000_000_000_000L),
|
||||
|
||||
entry(new BigDecimal("0e13"), 0L), // Fast path zero
|
||||
entry(new BigDecimal("0e64"), 0L),
|
||||
entry(new BigDecimal("0e1024"), 0L),
|
||||
|
||||
entry(new BigDecimal("10.000000000000000000000000000000000"), 10L));
|
||||
|
||||
for (var testCase : successCases.entrySet()) {
|
||||
BigDecimal bd = testCase.getKey();
|
||||
long expected = testCase.getValue();
|
||||
try {
|
||||
long longValueExact = bd.longValueExact();
|
||||
if (expected != longValueExact ||
|
||||
longValueExact != simpleLongValueExact(bd)) {
|
||||
failures++;
|
||||
System.err.println("Unexpected longValueExact result " + longValueExact +
|
||||
" on " + bd);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
failures++;
|
||||
System.err.println("Error on " + bd + "\tException message:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
return failures;
|
||||
}
|
||||
|
||||
private static int longValueExactExceptional() {
|
||||
int failures = 0;
|
||||
List<BigDecimal> exceptionalCases =
|
||||
List.of(new BigDecimal("9223372036854775808"), // Long.MAX_VALUE + 1
|
||||
new BigDecimal("9223372036854775808.0"),
|
||||
new BigDecimal("9223372036854775808.00"),
|
||||
new BigDecimal("-9223372036854775809"), // Long.MIN_VALUE - 1
|
||||
new BigDecimal("-9223372036854775808.1"),
|
||||
new BigDecimal("-9223372036854775808.01"),
|
||||
|
||||
new BigDecimal("9999999999999999999"),
|
||||
new BigDecimal("10000000000000000000"),
|
||||
|
||||
new BigDecimal("0.99"),
|
||||
new BigDecimal("0.999999999999999999999"));
|
||||
|
||||
for (BigDecimal bd : exceptionalCases) {
|
||||
try {
|
||||
long longValueExact = bd.longValueExact();
|
||||
failures++;
|
||||
System.err.println("Unexpected non-exceptional longValueExact on " + bd);
|
||||
} catch (ArithmeticException e) {
|
||||
// Success;
|
||||
}
|
||||
}
|
||||
return failures;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2019, 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 sun.rmi.server.UnicastRef;
|
||||
import sun.rmi.transport.LiveRef;
|
||||
import sun.rmi.transport.tcp.TCPEndpoint;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.net.InetAddress;
|
||||
import java.rmi.AccessException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import java.rmi.server.ObjID;
|
||||
import java.rmi.server.RemoteObjectInvocationHandler;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/* @test
|
||||
* @bug 8218453
|
||||
* @library ../../testlibrary
|
||||
* @modules java.rmi/sun.rmi.registry:+open java.rmi/sun.rmi.server:+open
|
||||
* java.rmi/sun.rmi.transport:+open java.rmi/sun.rmi.transport.tcp:+open
|
||||
* @summary Verify that Registry rejects non-local access for bind, unbind, rebind.
|
||||
* The test is manual because the (non-local) host running rmiregistry must be supplied as a property.
|
||||
* @run main/othervm -Dregistry.host=localhost NonLocalSkeletonTest
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @library ../../testlibrary
|
||||
* @modules java.rmi/sun.rmi.registry:+open java.rmi/sun.rmi.server:+open
|
||||
* java.rmi/sun.rmi.transport:+open java.rmi/sun.rmi.transport.tcp:+open
|
||||
* @summary Verify that Registry rejects non-local access for bind, unbind, rebind.
|
||||
* The test is manual because the (non-local) host running rmiregistry must be supplied as a property.
|
||||
* @run main/othervm/manual -Dregistry.host=rmi-registry-host NonLocalSkeletonTest
|
||||
*/
|
||||
|
||||
/**
|
||||
* Verify that access checks for Registry.bind(), .rebind(), and .unbind()
|
||||
* are prevented on remote access to the registry.
|
||||
*
|
||||
* This test is a manual test and uses a standard rmiregistry running
|
||||
* on a *different* host.
|
||||
* The test verifies that the access check is performed *before* the object to be
|
||||
* bound or rebound is deserialized.
|
||||
*
|
||||
* Login or ssh to the different host and invoke {@code $JDK_HOME/bin/rmiregistry}.
|
||||
* It will not show any output.
|
||||
*
|
||||
* On the first host modify the @run command above to replace "rmi-registry-host"
|
||||
* with the hostname or IP address of the different host and run the test with jtreg.
|
||||
*/
|
||||
public class NonLocalSkeletonTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String host = System.getProperty("registry.host");
|
||||
if (host == null || host.isEmpty()) {
|
||||
throw new RuntimeException("supply a remote host with -Dregistry.host=hostname");
|
||||
}
|
||||
|
||||
// Check if running the test on a local system; it only applies to remote
|
||||
String myHostName = InetAddress.getLocalHost().getHostName();
|
||||
Set<InetAddress> myAddrs = Set.of(InetAddress.getAllByName(myHostName));
|
||||
Set<InetAddress> hostAddrs = Set.of(InetAddress.getAllByName(host));
|
||||
boolean isLocal = (hostAddrs.stream().anyMatch(i -> myAddrs.contains(i))
|
||||
|| hostAddrs.stream().anyMatch(h -> h.isLoopbackAddress()));
|
||||
|
||||
int port;
|
||||
if (isLocal) {
|
||||
// Create a local Registry to use for the test
|
||||
port = TestLibrary.getUnusedRandomPort();
|
||||
Registry registry = LocateRegistry.createRegistry(port);
|
||||
System.out.printf("local registry port: %s%n", registry);
|
||||
} else {
|
||||
// Use regular rmi registry for non-local test
|
||||
port = Registry.REGISTRY_PORT;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Registry r = nonStaticRegistryProxy(host, port);
|
||||
|
||||
System.out.printf("RegistryRef: %s%n", r);
|
||||
|
||||
r.rebind("anyRef", r);
|
||||
if (!isLocal) {
|
||||
throw new RuntimeException("non-local bind should have failed to host: " + host);
|
||||
} else {
|
||||
System.out.printf("local rebind succeeded%n");
|
||||
}
|
||||
} catch (RemoteException rex) {
|
||||
if (!isLocal) {
|
||||
assertIsAccessException(rex);
|
||||
} else {
|
||||
throw rex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Returns a non-static proxy for the registry.
|
||||
* Follows the form of sun.rmi.server.Util.createProxy.
|
||||
* @param implClass the RegistryImpl
|
||||
* @param clientRef the registry reference
|
||||
**/
|
||||
static Registry nonStaticRegistryProxy(String host, int port) {
|
||||
final ClassLoader loader = Registry.class.getClassLoader();
|
||||
final Class<?>[] interfaces = new Class<?>[]{Registry.class};
|
||||
|
||||
LiveRef liveRef = new LiveRef(new ObjID(ObjID.REGISTRY_ID),
|
||||
new TCPEndpoint(host, port, null, null),
|
||||
false);
|
||||
|
||||
final InvocationHandler handler = new RemoteObjectInvocationHandler(new UnicastRef(liveRef));
|
||||
|
||||
PrivilegedAction<Registry> action = () -> (Registry) Proxy.newProxyInstance(loader,
|
||||
interfaces, handler);
|
||||
return AccessController.doPrivileged(action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the exception chain for the expected AccessException and message.
|
||||
* @param ex the exception from the remote invocation.
|
||||
*/
|
||||
private static void assertIsAccessException(Throwable ex) {
|
||||
Throwable t = ex;
|
||||
while (!(t instanceof AccessException) && t.getCause() != null) {
|
||||
t = t.getCause();
|
||||
}
|
||||
if (t instanceof AccessException) {
|
||||
String msg = t.getMessage();
|
||||
int asIndex = msg.indexOf("Registry");
|
||||
int rrIndex = msg.indexOf("Registry.Registry"); // Obsolete error text
|
||||
int disallowIndex = msg.indexOf("disallowed");
|
||||
int nonLocalHostIndex = msg.indexOf("non-local host");
|
||||
if (asIndex < 0 ||
|
||||
rrIndex != -1 ||
|
||||
disallowIndex < 0 ||
|
||||
nonLocalHostIndex < 0 ) {
|
||||
throw new RuntimeException("exception message is malformed", t);
|
||||
}
|
||||
System.out.printf("Found expected AccessException: %s%n%n", t);
|
||||
} else {
|
||||
throw new RuntimeException("AccessException did not occur when expected", ex);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user