mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8174109: Better queuing priorities
Reviewed-by: chegar, dfuchs, rriggs, alanb, robm, rhalade, jeff, ahgross
This commit is contained in:
parent
05331dc72f
commit
7d547d0ee4
14 changed files with 94 additions and 60 deletions
|
@ -1282,6 +1282,33 @@ public class ObjectInputStream
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the given array type and length to ensure that creation of such
|
||||
* an array is permitted by this ObjectInputStream. The arrayType argument
|
||||
* must represent an actual array type.
|
||||
*
|
||||
* This private method is called via SharedSecrets.
|
||||
*
|
||||
* @param arrayType the array type
|
||||
* @param arrayLength the array length
|
||||
* @throws NullPointerException if arrayType is null
|
||||
* @throws IllegalArgumentException if arrayType isn't actually an array type
|
||||
* @throws NegativeArraySizeException if arrayLength is negative
|
||||
* @throws InvalidClassException if the filter rejects creation
|
||||
*/
|
||||
private void checkArray(Class<?> arrayType, int arrayLength) throws InvalidClassException {
|
||||
Objects.requireNonNull(arrayType);
|
||||
if (! arrayType.isArray()) {
|
||||
throw new IllegalArgumentException("not an array type");
|
||||
}
|
||||
|
||||
if (arrayLength < 0) {
|
||||
throw new NegativeArraySizeException();
|
||||
}
|
||||
|
||||
filterCheck(arrayType, arrayLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide access to the persistent fields read from the input stream.
|
||||
*/
|
||||
|
@ -3982,6 +4009,10 @@ public class ObjectInputStream
|
|||
}
|
||||
}
|
||||
|
||||
static {
|
||||
SharedSecrets.setJavaObjectInputStreamAccess(ObjectInputStream::checkArray);
|
||||
}
|
||||
|
||||
private void validateDescriptor(ObjectStreamClass descriptor) {
|
||||
ObjectStreamClassValidator validating = validator;
|
||||
if (validating != null) {
|
||||
|
|
|
@ -38,6 +38,7 @@ import java.io.Serializable;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.UnaryOperator;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* Resizable-array implementation of the {@link Deque} interface. Array
|
||||
|
@ -1194,6 +1195,7 @@ public class ArrayDeque<E> extends AbstractCollection<E>
|
|||
|
||||
// Read in size and allocate array
|
||||
int size = s.readInt();
|
||||
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Object[].class, size + 1);
|
||||
elements = new Object[size + 1];
|
||||
this.tail = size;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2017, 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
|
||||
|
@ -28,6 +28,7 @@ package java.util;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.UnaryOperator;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* Resizable-array implementation of the {@code List} interface. Implements
|
||||
|
@ -814,6 +815,7 @@ public class ArrayList<E> extends AbstractList<E>
|
|||
|
||||
if (size > 0) {
|
||||
// like clone(), allocate array based upon size not capacity
|
||||
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Object[].class, size);
|
||||
Object[] elements = new Object[size];
|
||||
|
||||
// Read in all elements in the proper order.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2017, 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
|
||||
|
@ -34,6 +34,7 @@ import java.util.function.BiConsumer;
|
|||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* Hash table based implementation of the {@code Map} interface. This
|
||||
|
@ -1448,6 +1449,10 @@ public class HashMap<K,V> extends AbstractMap<K,V>
|
|||
float ft = (float)cap * lf;
|
||||
threshold = ((cap < MAXIMUM_CAPACITY && ft < MAXIMUM_CAPACITY) ?
|
||||
(int)ft : Integer.MAX_VALUE);
|
||||
|
||||
// Check Map.Entry[].class since it's the nearest public type to
|
||||
// what we're actually creating.
|
||||
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Map.Entry[].class, cap);
|
||||
@SuppressWarnings({"rawtypes","unchecked"})
|
||||
Node<K,V>[] tab = (Node<K,V>[])new Node[cap];
|
||||
table = tab;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -26,6 +26,7 @@
|
|||
package java.util;
|
||||
|
||||
import java.io.InvalidObjectException;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* This class implements the {@code Set} interface, backed by a hash table
|
||||
|
@ -322,6 +323,13 @@ public class HashSet<E>
|
|||
capacity = (int) Math.min(size * Math.min(1 / loadFactor, 4.0f),
|
||||
HashMap.MAXIMUM_CAPACITY);
|
||||
|
||||
// Constructing the backing map will lazily create an array when the first element is
|
||||
// added, so check it before construction. Call HashMap.tableSizeFor to compute the
|
||||
// actual allocation size. Check Map.Entry[].class since it's the nearest public type to
|
||||
// what is actually created.
|
||||
SharedSecrets.getJavaObjectInputStreamAccess()
|
||||
.checkArray(s, Map.Entry[].class, HashMap.tableSizeFor(capacity));
|
||||
|
||||
// Create backing HashMap
|
||||
map = (((HashSet<?>)this) instanceof LinkedHashSet ?
|
||||
new LinkedHashMap<>(capacity, loadFactor) :
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2017, 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
|
||||
|
@ -29,6 +29,7 @@ import java.io.*;
|
|||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.BiFunction;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* This class implements a hash table, which maps keys to values. Any
|
||||
|
@ -1291,6 +1292,10 @@ public class Hashtable<K,V>
|
|||
if (length > elements && (length & 1) == 0)
|
||||
length--;
|
||||
length = Math.min(length, origlength);
|
||||
|
||||
// Check Map.Entry[].class since it's the nearest public type to
|
||||
// what we're actually creating.
|
||||
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Map.Entry[].class, length);
|
||||
table = new Entry<?,?>[length];
|
||||
threshold = (int)Math.min(length * loadFactor, MAX_ARRAY_SIZE + 1);
|
||||
count = 0;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2017, 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
|
||||
|
@ -29,6 +29,7 @@ import java.lang.reflect.Array;
|
|||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* This class implements the {@code Map} interface with a hash table, using
|
||||
|
@ -1304,7 +1305,9 @@ public class IdentityHashMap<K,V>
|
|||
if (size < 0)
|
||||
throw new java.io.StreamCorruptedException
|
||||
("Illegal mappings count: " + size);
|
||||
init(capacity(size));
|
||||
int cap = capacity(size);
|
||||
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Object[].class, cap);
|
||||
init(cap);
|
||||
|
||||
// Read the keys and values, and put the mappings in the table
|
||||
for (int i=0; i<size; i++) {
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.util.function.BiFunction;
|
|||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.UnaryOperator;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
/**
|
||||
|
@ -885,6 +886,7 @@ final class CollSer implements Serializable {
|
|||
throw new InvalidObjectException("negative length " + len);
|
||||
}
|
||||
|
||||
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(ois, Object[].class, len);
|
||||
Object[] a = new Object[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
a[i] = ois.readObject();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -26,6 +26,7 @@
|
|||
package java.util;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* An unbounded priority {@linkplain Queue queue} based on a priority heap.
|
||||
|
@ -795,6 +796,7 @@ public class PriorityQueue<E> extends AbstractQueue<E>
|
|||
// Read in (and discard) array length
|
||||
s.readInt();
|
||||
|
||||
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Object[].class, size);
|
||||
queue = new Object[size];
|
||||
|
||||
// Read in all elements.
|
||||
|
|
|
@ -42,6 +42,7 @@ import java.util.function.BiConsumer;
|
|||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
import jdk.internal.util.xml.PropertiesDefaultHandler;
|
||||
|
||||
/**
|
||||
|
@ -1441,6 +1442,16 @@ class Properties extends Hashtable<Object,Object> {
|
|||
throw new StreamCorruptedException("Illegal # of Elements: " + elements);
|
||||
}
|
||||
|
||||
// Constructing the backing map will lazily create an array when the first element is
|
||||
// added, so check it before construction. Note that CHM's constructor takes a size
|
||||
// that is the number of elements to be stored -- not the table size -- so it must be
|
||||
// inflated by the default load factor of 0.75, then inflated to the next power of two.
|
||||
// (CHM uses the same power-of-two computation as HashMap, and HashMap.tableSizeFor is
|
||||
// accessible here.) Check Map.Entry[].class since it's the nearest public type to
|
||||
// what is actually created.
|
||||
SharedSecrets.getJavaObjectInputStreamAccess()
|
||||
.checkArray(s, Map.Entry[].class, HashMap.tableSizeFor((int)(elements / 0.75)));
|
||||
|
||||
// create CHM of appropriate capacity
|
||||
map = new ConcurrentHashMap<>(elements);
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ import java.util.Spliterators;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.UnaryOperator;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* A thread-safe variant of {@link java.util.ArrayList} in which all mutative
|
||||
|
@ -933,6 +934,7 @@ public class CopyOnWriteArrayList<E>
|
|||
|
||||
// Read in array length and allocate array
|
||||
int len = s.readInt();
|
||||
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Object[].class, len);
|
||||
Object[] elements = new Object[len];
|
||||
|
||||
// Read in all elements in the proper order.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue