This commit is contained in:
Lana Steuck 2011-11-18 15:49:09 -08:00
commit 7bcad978ba
129 changed files with 4746 additions and 1975 deletions

View file

@ -0,0 +1,79 @@
/*
* Copyright (c) 2011, 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 4268317
* @summary Test if Reference.enqueue() works properly with GC
*/
import java.lang.ref.*;
public class ReferenceEnqueue {
public static void main(String args[]) throws Exception {
for (int i=0; i < 5; i++)
new WeakRef().run();
System.out.println("Test passed.");
}
static class WeakRef {
final ReferenceQueue<Object> queue = new ReferenceQueue<Object>();
final Reference<Object> ref;
final int iterations = 1000;
WeakRef() {
this.ref = new WeakReference<Object>(new Object(), queue);
}
void run() throws InterruptedException {
System.gc();
for (int i = 0; i < iterations; i++) {
System.gc();
if (ref.isEnqueued()) {
break;
}
Thread.sleep(100);
}
if (ref.isEnqueued() == false) {
// GC have not enqueued refWeak for the timeout period
System.out.println("Reference not enqueued yet");
return;
}
if (ref.enqueue() == true) {
// enqueue() should return false since
// ref is already enqueued by the GC
throw new RuntimeException("Error: enqueue() returned true;"
+ " expected false");
}
if (queue.poll() == null) {
// poll() should return ref enqueued by the GC
throw new RuntimeException("Error: poll() returned null;"
+ " expected ref object");
}
}
}
}

View file

@ -0,0 +1,201 @@
/* Copyright (c) 2011, 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 4243978
* @summary Test if Reference.enqueue() works properly with pending references
*/
import java.lang.ref.*;
public class ReferenceEnqueuePending {
static class NumberedWeakReference extends WeakReference<Integer> {
// Add an integer to identify the weak reference object.
int number;
NumberedWeakReference(Integer referent, ReferenceQueue<Integer> q, int i) {
super(referent, q);
number = i;
}
}
final static boolean debug = System.getProperty("test.debug") != null;
final static int iterations = 1000;
final static int gc_trigger = 99;
static int[] a = new int[2 * iterations];
// Keep all weak references alive with the following array.
static NumberedWeakReference[] b = new NumberedWeakReference[iterations];
public static void main(String[] argv) throws Exception {
if (debug) {
System.out.println("Starting the test.");
}
// Raise thread priority to match the referenceHandler
// priority, so that they can race also on a uniprocessor.
raisePriority();
ReferenceQueue<Integer> refQueue = new ReferenceQueue<>();
// Our objective is to let the mutator enqueue
// a Reference object that may already be in the
// pending state because of having been identified
// as weakly reachable at a previous garbage collection.
// To this end, we create many Reference objects, each with a
// a unique integer object as its referant.
// We let the referents become eligible for collection,
// while racing with the garbage collector which may
// have pended some of these Reference objects.
// Finally we check that all of the Reference objects
// end up on the their queue. The test was originally
// submitted to show that such races could break the
// pending list and/or the reference queue, because of sharing
// the same link ("next") for maintaining both lists, thus
// losing some of the Reference objects on either queue.
Integer obj = new Integer(0);
NumberedWeakReference weaky = new NumberedWeakReference(obj, refQueue, 0);
for (int i = 1; i < iterations; i++) {
// Create a new object, dropping the onlY strong reference to
// the previous Integer object.
obj = new Integer(i);
// Trigger gc each gc_trigger iterations.
if ((i % gc_trigger) == 0) {
forceGc(0);
}
// Enqueue every other weaky.
if ((i % 2) == 0) {
weaky.enqueue();
}
// Remember the Reference objects, for testing later.
b[i - 1] = weaky;
// Get a new weaky for the Integer object just
// created, which may be explicitly enqueued in
// our next trip around the loop.
weaky = new NumberedWeakReference(obj, refQueue, i);
}
// Do a final collection to discover and process all
// Reference objects created above, allowing enough time
// for the ReferenceHandler thread to queue the References.
forceGc(100);
forceGc(100);
// Verify that all WeakReference objects ended up queued.
checkResult(refQueue, obj, iterations-1);
System.out.println("Test passed.");
}
private static void checkResult(ReferenceQueue<Integer> queue,
Integer obj,
int expected) {
if (debug) {
System.out.println("Reading the queue");
}
// Empty the queue and record numbers into a[];
NumberedWeakReference weakRead = (NumberedWeakReference) queue.poll();
int length = 0;
while (weakRead != null) {
a[length++] = weakRead.number;
weakRead = (NumberedWeakReference) queue.poll();
}
if (debug) {
System.out.println("Reference Queue had " + length + " elements");
}
// Use the last Reference object of those created above, so as to keep it "alive".
System.out.println("I must write " + obj + " to prevent compiler optimizations.");
// verify the queued references: all but the last Reference object
// should have been in the queue.
if (debug) {
System.out.println("Start of final check");
}
// Sort the first "length" elements in array "a[]".
sort(length);
boolean fail = (length != expected);
for (int i = 0; i < length; i++) {
if (a[i] != i) {
if (debug) {
System.out.println("a[" + i + "] is not " + i + " but " + a[i]);
}
fail = true;
}
}
if (fail) {
printMissingElements(length, expected);
throw new RuntimeException("TEST FAILED: only " + length
+ " reference objects have been queued out of "
+ expected);
}
}
private static void printMissingElements(int length, int expected) {
System.out.println("The following numbers were not found in the reference queue: ");
int missing = 0;
int element = 0;
for (int i = 0; i < length; i++) {
while ((a[i] != element) & (element < expected)) {
System.out.print(element + " ");
if (missing % 20 == 19) {
System.out.println(" ");
}
missing++;
element++;
}
element++;
}
System.out.print("\n");
}
private static void forceGc(long millis) throws InterruptedException {
Runtime.getRuntime().gc();
Thread.sleep(millis);
}
// Bubble sort the first "length" elements in array "a".
private static void sort(int length) {
int hold;
if (debug) {
System.out.println("Sorting. Length=" + length);
}
for (int pass = 1; pass < length; pass++) { // passes over the array
for (int i = 0; i < length - pass; i++) { // a single pass
if (a[i] > a[i + 1]) { // then swap
hold = a[i];
a[i] = a[i + 1];
a[i + 1] = hold;
}
} // End of i loop
} // End of pass loop
}
// Raise thread priority so as to increase the
// probability of the mutator succeeding in enqueueing
// an object that is still in the pending state.
// This is (probably) only required for a uniprocessor.
static void raisePriority() {
Thread tr = Thread.currentThread();
tr.setPriority(Thread.MAX_PRIORITY);
}
} // End of class ReferenceEnqueuePending

View file

@ -23,7 +23,7 @@
/* @test
* @summary Check that error cases are replaced correctly in String/ISR/OSW
* @bug 4457851
* @bug 4457851 7096080
*
* @build Errors Util
* @run main Errors
@ -193,11 +193,9 @@ public class Errors {
t.test("\uFFFF", new byte[] { (byte)0xEF, (byte)0xBF, (byte)0xBF });
t.test(new byte[] { X, (byte)0x7f, Y }, "x\u007Fy");
t.test(new byte[] { X, (byte)0x80, Y }, "x\uFFFDy");
t.test(new byte[] { (byte)0xf0, (byte)0xf0 }, "\uFFFD");
}
public static void main(String[] args) throws Exception {
test_US_ASCII(new TestString("US-ASCII"));
test_US_ASCII(new TestStream("US-ASCII"));

View file

@ -0,0 +1,351 @@
/*
* Copyright (c) 2011, 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 4533691
* @summary Unit test for Collections.emptySortedSet
*/
import java.lang.reflect.Method;
import java.math.BigInteger;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.SortedSet;
import java.util.TreeSet;
public class EmptySortedSet {
static int status = 0;
private static final String FAILED = " failed. ";
private static final String PERIOD = ".";
private final String thisClassName = this.getClass().getName();
public static void main(String[] args) throws Exception {
new EmptySortedSet();
}
public EmptySortedSet() throws Exception {
run();
}
/**
* Returns {@code true} if the {@link Object} passed in is an empty
* {@link SortedSet}.
*
* @param obj the object to test
* @return {@code true} if the {@link Object} is an empty {@link SortedSet}
* otherwise {@code false}.
*/
private boolean isEmptySortedSet(Object obj) {
boolean isEmptySortedSet = false;
// We determine if the object is an empty sorted set by testing if it's
// an instance of SortedSet, and if so, if it's empty. Currently the
// testing doesn't include checks of the other methods.
if (obj instanceof SortedSet) {
SortedSet ss = (SortedSet) obj;
if ((ss.isEmpty()) && (ss.size() == 0)) {
isEmptySortedSet = true;
}
}
return isEmptySortedSet;
}
private void run() throws Exception {
Method[] methods = this.getClass().getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
String methodName = method.getName();
if (methodName.startsWith("test")) {
try {
Object obj = method.invoke(this, new Object[0]);
} catch(Exception e) {
throw new Exception(this.getClass().getName() + "." +
methodName + " test failed, test exception "
+ "follows\n" + e.getCause());
}
}
}
}
private void throwException(String methodName, String reason)
throws Exception
{
StringBuilder sb = new StringBuilder(thisClassName);
sb.append(PERIOD);
sb.append(methodName);
sb.append(FAILED);
sb.append(reason);
throw new Exception(sb.toString());
}
/**
*
*/
private void test00() throws Exception {
//throwException("test00", "This test has not been implemented yet.");
}
/**
* Tests that the comparator is {@code null}.
*/
private void testComparatorIsNull() throws Exception {
SortedSet sortedSet = Collections.emptySortedSet();
Comparator comparator = sortedSet.comparator();
if (comparator != null) {
throwException("testComparatorIsNull", "Comparator is not null.");
}
}
/**
* Tests that the contains method returns {@code false}.
*/
private void testContains() throws Exception {
SortedSet sortedSet = Collections.emptySortedSet();
if (sortedSet.contains(new Object())) {
throwException("testContains", "Should not contain any elements.");
}
}
/**
* Tests that the containsAll method returns {@code false}.
*/
private void testContainsAll() throws Exception {
SortedSet sortedSet = Collections.emptySortedSet();
TreeSet treeSet = new TreeSet();
treeSet.add("1");
treeSet.add("2");
treeSet.add("3");
if (sortedSet.containsAll(treeSet)) {
throwException("testContainsAll",
"Should not contain any elements.");
}
}
/**
* Tests that the iterator is empty.
*/
private void testEmptyIterator() throws Exception {
SortedSet sortedSet = Collections.emptySortedSet();
Iterator emptyIterator = sortedSet.iterator();
if ((emptyIterator != null) && (emptyIterator.hasNext())) {
throwException("testEmptyIterator", "The iterator is not empty.");
}
}
/**
* Tests that the set is empty.
*/
private void testIsEmpty() throws Exception {
SortedSet sortedSet = Collections.emptySortedSet();
if ((sortedSet != null) && (!sortedSet.isEmpty())) {
throwException("testSizeIsZero", "The set is not empty.");
}
}
/**
* Tests that the first() method throws NoSuchElementException
*/
private void testFirst() throws Exception {
SortedSet sortedSet = Collections.emptySortedSet();
try {
sortedSet.first();
throwException("testFirst",
"NoSuchElemenException was not thrown.");
} catch(NoSuchElementException nsee) {
// Do nothing
}
}
/**
* Tests the headSet() method.
*/
private void testHeadSet() throws Exception {
SortedSet sortedSet = Collections.emptySortedSet();
SortedSet ss;
try {
ss = sortedSet.headSet(null);
throwException("testHeadSet",
"Must throw NullPointerException for null element");
} catch(NullPointerException npe) {
// Do nothing
}
try {
ss = sortedSet.headSet(new Object());
throwException("testHeadSet",
"Must throw ClassCastException for non-Comparable element");
} catch(ClassCastException cce) {
// Do nothing.
}
ss = sortedSet.headSet("1");
if ((ss == null) || !isEmptySortedSet(ss)) {
throwException("testHeadSet",
"Returned value is null or not an EmptySortedSet.");
}
}
/**
* Tests that the last() method throws NoSuchElementException
*/
private void testLast() throws Exception {
SortedSet sortedSet = Collections.emptySortedSet();
try {
sortedSet.last();
throwException("testLast",
"NoSuchElemenException was not thrown.");
} catch(NoSuchElementException nsee) {
// Do nothing
}
}
/**
* Tests that the size is 0.
*/
private void testSizeIsZero() throws Exception {
SortedSet sortedSet = Collections.emptySortedSet();
int size = sortedSet.size();
if (size > 0) {
throwException("testSizeIsZero",
"The size of the set is greater then 0.");
}
}
/**
* Tests the subSet() method.
*/
private void testSubSet() throws Exception {
SortedSet sortedSet = Collections.emptySortedSet();
SortedSet ss = sortedSet.headSet("1");
try {
ss = sortedSet.subSet(null, BigInteger.TEN);
ss = sortedSet.subSet(BigInteger.ZERO, null);
ss = sortedSet.subSet(null, null);
throwException("testSubSet",
"Must throw NullPointerException for null element");
} catch(NullPointerException npe) {
// Do nothing
}
try {
Object obj1 = new Object();
Object obj2 = new Object();
ss = sortedSet.subSet(obj1, BigInteger.TEN);
ss = sortedSet.subSet(BigInteger.ZERO, obj2);
ss = sortedSet.subSet(obj1, obj2);
throwException("testSubSet",
"Must throw ClassCastException for parameter which is "
+ "not Comparable.");
} catch(ClassCastException cce) {
// Do nothing.
}
try {
ss = sortedSet.subSet(BigInteger.ZERO, BigInteger.ZERO);
ss = sortedSet.subSet(BigInteger.TEN, BigInteger.ZERO);
throwException("testSubSet",
"Must throw IllegalArgumentException when fromElement is "
+ "not less then then toElement.");
} catch(IllegalArgumentException iae) {
// Do nothing.
}
ss = sortedSet.subSet(BigInteger.ZERO, BigInteger.TEN);
if (!isEmptySortedSet(ss)) {
throw new Exception("Returned value is not empty sorted set.");
}
}
/**
* Tests the tailSet() method.
*/
private void testTailSet() throws Exception {
SortedSet sortedSet = Collections.emptySortedSet();
SortedSet ss;
try {
ss = sortedSet.tailSet(null);
throwException("testTailSet",
"Must throw NullPointerException for null element");
} catch(NullPointerException npe) {
// Do nothing
}
try {
SortedSet ss2 = sortedSet.tailSet(new Object());
throwException("testTailSet",
"Must throw ClassCastException for non-Comparable element");
} catch(ClassCastException cce) {
// Do nothing.
}
ss = sortedSet.tailSet("1");
if ((ss == null) || !isEmptySortedSet(ss)) {
throwException("testTailSet",
"Returned value is null or not an EmptySortedSet.");
}
}
/**
* Tests that the array has a size of 0.
*/
private void testToArray() throws Exception {
SortedSet sortedSet = Collections.emptySortedSet();
Object[] emptySortedSetArray = sortedSet.toArray();
if ((emptySortedSetArray == null) || (emptySortedSetArray.length > 0)) {
throwException("testToArray",
"Returned null array or array with length > 0.");
}
String[] strings = new String[2];
strings[0] = "1";
strings[1] = "2";
emptySortedSetArray = sortedSet.toArray(strings);
if ((emptySortedSetArray == null) || (emptySortedSetArray[0] != null)) {
throwException("testToArray",
"Returned null array or array with length > 0.");
}
}
}

View file

@ -128,18 +128,20 @@ public class CurrencyTest {
checkCountryCurrency(country1[i], currency1[i]);
}
// check currency changes
String[] switchOverCtry = {"DE", "FR", "ES", "IT", "NL", "BE", "TR", "RO", "AZ", "MZ", "GH", "VE"};
String[] switchOverOld = {"DEM", "FRF", "ESP", "ITL", "NLG", "BEF", "TRL", "ROL", "AZM", "MZM", "GHC", "VEB"};
String[] switchOverNew = {"EUR", "EUR", "EUR", "EUR", "EUR", "EUR", "TRY", "RON", "AZN", "MZN", "GHS", "VEF"};
String[] switchOverTZ = {"Europe/Paris", "Europe/Paris", "Europe/Paris", "Europe/Paris",
"Europe/Paris", "Europe/Paris", "Asia/Istanbul", "Europe/Bucharest",
"Asia/Baku", "Africa/Maputo", "Africa/Accra", "America/Caracas"};
int[] switchOverYear = {2002, 2002, 2002, 2002, 2002, 2002, 2005, 2005, 2006, 2006, 2007, 2008};
int[] switchOverMonth = {Calendar.JANUARY, Calendar.JANUARY, Calendar.JANUARY, Calendar.JANUARY,
Calendar.JANUARY, Calendar.JANUARY, Calendar.JANUARY, Calendar.JULY,
Calendar.JANUARY, Calendar.JULY, Calendar.JULY, Calendar.JANUARY};
int[] switchOverDay = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
/*
* check currency changes
* In current implementation, there is no data of old currency and transition date at jdk/src/share/classes/java/util/CurrencyData.properties.
* So, all the switch data arrays are empty. In the future, if data of old currency and transition date are necessary for any country, the
* arrays here can be updated so that the program can check the currency switch.
*/
String[] switchOverCtry = {};
String[] switchOverOld = {};
String[] switchOverNew = {};
String[] switchOverTZ = {};
int[] switchOverYear = {};
int[] switchOverMonth = {};
int[] switchOverDay = {};
for (int i = 0; i < switchOverCtry.length; i++) {
TimeZone.setDefault(TimeZone.getTimeZone(switchOverTZ[i]));
Calendar date = new GregorianCalendar(switchOverYear[i], switchOverMonth[i], switchOverDay[i]);

View file

@ -92,7 +92,7 @@ public class ValidateISO4217 {
/* Codes that are obsolete, do not have related country */
static final String otherCodes =
"ADP-AFA-ATS-AYM-BEF-BGL-BOV-BYB-CLF-CUC-CYP-DEM-EEK-ESP-FIM-FRF-GRD-GWP-IEP-ITL-LUF-MGF-MTL-MXV-NLG-PTE-RUR-SDD-SIT-SKK-SRG-TMM-TPE-TRL-VEF-USN-USS-XAG-XAU-XBA-XBB-XBC-XBD-XDR-XFO-XFU-XPD-XPT-XSU-XTS-XUA-XXX-YUM-ZWD-ZWN-ZWR";
"ADP-AFA-ATS-AYM-AZM-BEF-BGL-BOV-BYB-CLF-CUC-CYP-DEM-EEK-ESP-FIM-FRF-GHC-GRD-GWP-IEP-ITL-LUF-MGF-MTL-MXV-MZM-NLG-PTE-ROL-RUR-SDD-SIT-SKK-SRG-TMM-TPE-TRL-VEF-USN-USS-VEB-XAG-XAU-XBA-XBB-XBC-XBD-XDR-XFO-XFU-XPD-XPT-XSU-XTS-XUA-XXX-YUM-ZWD-ZWN-ZWR";
static boolean err = false;

View file

@ -23,7 +23,7 @@ AW AWG 533 2
AU AUD 36 2
AT EUR 978 2
# MA 129
AZ AZM 31 2 2005-12-31-20-00-00 AZN 944 2
AZ AZN 944 2
BS BSD 44 2
BH BHD 48 3
BD BDT 50 2
@ -96,7 +96,7 @@ GA XAF 950 0
GM GMD 270 2
GE GEL 981 2
DE EUR 978 2
GH GHC 288 2 2007-07-01-00-00-00 GHS 936 2
GH GHS 936 2
GI GIP 292 2
GR EUR 978 2
GL DKK 208 2
@ -166,7 +166,7 @@ MN MNT 496 2
MS XCD 951 2
MA MAD 504 2
# MA 130
MZ MZM 508 2 2006-06-30-22-00-00 MZN 943 2
MZ MZN 943 2
MM MMK 104 2
# MA 134
ME EUR 978 2
@ -200,7 +200,7 @@ PT EUR 978 2
PR USD 840 2
QA QAR 634 2
RE EUR 978 2
RO ROL 946 2 2005-06-30-21-00-00 RON 946 2
RO RON 946 2
RU RUB 643 2
RW RWF 646 0
SH SHP 654 2
@ -266,7 +266,7 @@ UM USD 840 2
UY UYU 858 2
UZ UZS 860 2
VU VUV 548 0
VE VEB 862 2 2008-01-01-04-00-00 VEF 937 2
VE VEF 937 2
VN VND 704 2
VG USD 840 2
VI USD 840 2