--- a/.hgtags Fri Jun 14 20:56:48 2019 -0400
+++ b/.hgtags Fri Jun 14 21:04:16 2019 -0400
@@ -563,3 +563,4 @@
b034d2dee5fc93d42a81b65e58ce3f91e42586ff jdk-13+23
7e2238451585029680f126ccbb46d01f2ff5607f jdk-13+24
22b3b7983adab54e318f75aeb94471f7a4429c1e jdk-14+0
+2f4e214781a1d597ed36bf5a36f20928c6c82996 jdk-14+1
--- a/src/hotspot/share/gc/shared/c2/barrierSetC2.hpp Fri Jun 14 20:56:48 2019 -0400
+++ b/src/hotspot/share/gc/shared/c2/barrierSetC2.hpp Fri Jun 14 21:04:16 2019 -0400
@@ -308,7 +308,6 @@
virtual bool escape_add_to_con_graph(ConnectionGraph* conn_graph, PhaseGVN* gvn, Unique_Node_List* delayed_worklist, Node* n, uint opcode) const { return false; }
virtual bool escape_add_final_edges(ConnectionGraph* conn_graph, PhaseGVN* gvn, Node* n, uint opcode) const { return false; }
virtual bool escape_has_out_with_unsafe_object(Node* n) const { return false; }
- virtual bool escape_is_barrier_node(Node* n) const { return false; }
virtual bool matcher_find_shared_visit(Matcher* matcher, Matcher::MStack& mstack, Node* n, uint opcode, bool& mem_op, int& mem_addr_idx) const { return false; };
virtual bool matcher_find_shared_post_visit(Matcher* matcher, Node* n, uint opcode) const { return false; };
--- a/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp Fri Jun 14 20:56:48 2019 -0400
+++ b/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp Fri Jun 14 21:04:16 2019 -0400
@@ -1194,10 +1194,6 @@
}
-bool ShenandoahBarrierSetC2::escape_is_barrier_node(Node* n) const {
- return n->Opcode() == Op_ShenandoahLoadReferenceBarrier;
-}
-
bool ShenandoahBarrierSetC2::matcher_find_shared_post_visit(Matcher* matcher, Node* n, uint opcode) const {
switch (opcode) {
case Op_ShenandoahCompareAndExchangeP:
--- a/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.hpp Fri Jun 14 20:56:48 2019 -0400
+++ b/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.hpp Fri Jun 14 21:04:16 2019 -0400
@@ -144,7 +144,6 @@
virtual bool escape_add_to_con_graph(ConnectionGraph* conn_graph, PhaseGVN* gvn, Unique_Node_List* delayed_worklist, Node* n, uint opcode) const;
virtual bool escape_add_final_edges(ConnectionGraph* conn_graph, PhaseGVN* gvn, Node* n, uint opcode) const;
virtual bool escape_has_out_with_unsafe_object(Node* n) const;
- virtual bool escape_is_barrier_node(Node* n) const;
virtual bool matcher_find_shared_post_visit(Matcher* matcher, Node* n, uint opcode) const;
virtual bool matcher_is_store_load_barrier(Node* x, uint xop) const;
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp Fri Jun 14 20:56:48 2019 -0400
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp Fri Jun 14 21:04:16 2019 -0400
@@ -1279,7 +1279,12 @@
// First, we process all GC roots. This populates the work stack with initial objects.
ShenandoahAllRootScanner rp(1, ShenandoahPhaseTimings::_num_phases);
ObjectIterateScanRootClosure oops(&_aux_bit_map, &oop_stack);
- rp.roots_do_unchecked(&oops);
+
+ if (unload_classes()) {
+ rp.strong_roots_do_unchecked(&oops);
+ } else {
+ rp.roots_do_unchecked(&oops);
+ }
// Work through the oop stack to traverse heap.
while (! oop_stack.is_empty()) {
--- a/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.hpp Fri Jun 14 20:56:48 2019 -0400
+++ b/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.hpp Fri Jun 14 21:04:16 2019 -0400
@@ -148,6 +148,7 @@
void roots_do(uint worker_id, OopClosure* oops, CLDClosure* clds, CodeBlobClosure* code, ThreadClosure* tc = NULL);
// For heap object iteration
void roots_do_unchecked(OopClosure* cl);
+ void strong_roots_do_unchecked(OopClosure* cl);
};
typedef ShenandoahRootScanner<ShenandoahAllCodeRootsIterator> ShenandoahAllRootScanner;
--- a/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.inline.hpp Fri Jun 14 20:56:48 2019 -0400
+++ b/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.inline.hpp Fri Jun 14 21:04:16 2019 -0400
@@ -126,6 +126,19 @@
}
template <typename ITR>
+void ShenandoahRootScanner<ITR>::strong_roots_do_unchecked(OopClosure* oops) {
+ CLDToOopClosure clds(oops, ClassLoaderData::_claim_strong);
+ MarkingCodeBlobClosure code(oops, !CodeBlobToOopClosure::FixRelocations);
+ ShenandoahParallelOopsDoThreadClosure tc_cl(oops, &code, NULL);
+ ResourceMark rm;
+
+ _serial_roots.oops_do(oops, 0);
+ _jni_roots.oops_do(oops, 0);
+ _cld_roots.clds_do(&clds, NULL, 0);
+ _thread_roots.threads_do(&tc_cl, 0);
+}
+
+template <typename ITR>
void ShenandoahRootScanner<ITR>::strong_roots_do(uint worker_id, OopClosure* oops, CLDClosure* clds, CodeBlobClosure* code, ThreadClosure* tc) {
assert(ShenandoahHeap::heap()->unload_classes(), "Should be used during class unloading");
ShenandoahParallelOopsDoThreadClosure tc_cl(oops, code, tc);
--- a/src/hotspot/share/opto/escape.cpp Fri Jun 14 20:56:48 2019 -0400
+++ b/src/hotspot/share/opto/escape.cpp Fri Jun 14 21:04:16 2019 -0400
@@ -2346,8 +2346,7 @@
assert(opcode == Op_ConP || opcode == Op_ThreadLocal ||
opcode == Op_CastX2P || uncast_base->is_DecodeNarrowPtr() ||
(uncast_base->is_Mem() && (uncast_base->bottom_type()->isa_rawptr() != NULL)) ||
- (uncast_base->is_Proj() && uncast_base->in(0)->is_Allocate()) ||
- BarrierSet::barrier_set()->barrier_set_c2()->escape_is_barrier_node(uncast_base), "sanity");
+ (uncast_base->is_Proj() && uncast_base->in(0)->is_Allocate()), "sanity");
}
}
return base;
@@ -3085,7 +3084,6 @@
n->is_CheckCastPP() ||
n->is_EncodeP() ||
n->is_DecodeN() ||
- BarrierSet::barrier_set()->barrier_set_c2()->escape_is_barrier_node(n) ||
(n->is_ConstraintCast() && n->Opcode() == Op_CastPP)) {
if (visited.test_set(n->_idx)) {
assert(n->is_Phi(), "loops only through Phi's");
@@ -3156,7 +3154,6 @@
use->is_CheckCastPP() ||
use->is_EncodeNarrowPtr() ||
use->is_DecodeNarrowPtr() ||
- BarrierSet::barrier_set()->barrier_set_c2()->escape_is_barrier_node(use) ||
(use->is_ConstraintCast() && use->Opcode() == Op_CastPP)) {
alloc_worklist.append_if_missing(use);
#ifdef ASSERT
--- a/src/hotspot/share/opto/type.cpp Fri Jun 14 20:56:48 2019 -0400
+++ b/src/hotspot/share/opto/type.cpp Fri Jun 14 21:04:16 2019 -0400
@@ -2109,7 +2109,7 @@
const TypeAry *a = t->is_ary();
return TypeAry::make(_elem->meet_speculative(a->_elem),
_size->xmeet(a->_size)->is_int(),
- _stable & a->_stable);
+ _stable && a->_stable);
}
case Top:
break;
@@ -3879,7 +3879,7 @@
bool subtype_exact = false;
if( tinst_klass->equals(this_klass) ) {
subtype = this_klass;
- subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
+ subtype_exact = below_centerline(ptr) ? (this_xk && tinst_xk) : (this_xk || tinst_xk);
} else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
subtype = this_klass; // Pick subtyping class
subtype_exact = this_xk;
@@ -4361,7 +4361,7 @@
if (below_centerline(this->_ptr)) {
xk = this->_klass_is_exact;
} else {
- xk = (tap->_klass_is_exact | this->_klass_is_exact);
+ xk = (tap->_klass_is_exact || this->_klass_is_exact);
}
return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative, depth);
case Constant: {
--- a/src/java.base/share/classes/java/util/HashMap.java Fri Jun 14 20:56:48 2019 -0400
+++ b/src/java.base/share/classes/java/util/HashMap.java Fri Jun 14 21:04:16 2019 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -911,6 +911,74 @@
return ks;
}
+ /**
+ * Prepares the array for {@link Collection#toArray(Object[])} implementation.
+ * If supplied array is smaller than this map size, a new array is allocated.
+ * If supplied array is bigger than this map size, a null is written at size index.
+ *
+ * @param a an original array passed to {@code toArray()} method
+ * @param <T> type of array elements
+ * @return an array ready to be filled and returned from {@code toArray()} method.
+ */
+ @SuppressWarnings("unchecked")
+ final <T> T[] prepareArray(T[] a) {
+ int size = this.size;
+ if (a.length < size) {
+ return (T[]) java.lang.reflect.Array
+ .newInstance(a.getClass().getComponentType(), size);
+ }
+ if (a.length > size) {
+ a[size] = null;
+ }
+ return a;
+ }
+
+ /**
+ * Fills an array with this map keys and returns it. This method assumes
+ * that input array is big enough to fit all the keys. Use
+ * {@link #prepareArray(Object[])} to ensure this.
+ *
+ * @param a an array to fill
+ * @param <T> type of array elements
+ * @return supplied array
+ */
+ <T> T[] keysToArray(T[] a) {
+ Object[] r = a;
+ Node<K,V>[] tab;
+ int idx = 0;
+ if (size > 0 && (tab = table) != null) {
+ for (Node<K,V> e : tab) {
+ for (; e != null; e = e.next) {
+ r[idx++] = e.key;
+ }
+ }
+ }
+ return a;
+ }
+
+ /**
+ * Fills an array with this map values and returns it. This method assumes
+ * that input array is big enough to fit all the values. Use
+ * {@link #prepareArray(Object[])} to ensure this.
+ *
+ * @param a an array to fill
+ * @param <T> type of array elements
+ * @return supplied array
+ */
+ <T> T[] valuesToArray(T[] a) {
+ Object[] r = a;
+ Node<K,V>[] tab;
+ int idx = 0;
+ if (size > 0 && (tab = table) != null) {
+ for (Node<K,V> e : tab) {
+ for (; e != null; e = e.next) {
+ r[idx++] = e.value;
+ }
+ }
+ }
+ return a;
+ }
+
final class KeySet extends AbstractSet<K> {
public final int size() { return size; }
public final void clear() { HashMap.this.clear(); }
@@ -922,6 +990,15 @@
public final Spliterator<K> spliterator() {
return new KeySpliterator<>(HashMap.this, 0, -1, 0, 0);
}
+
+ public Object[] toArray() {
+ return keysToArray(new Object[size]);
+ }
+
+ public <T> T[] toArray(T[] a) {
+ return keysToArray(prepareArray(a));
+ }
+
public final void forEach(Consumer<? super K> action) {
Node<K,V>[] tab;
if (action == null)
@@ -970,6 +1047,15 @@
public final Spliterator<V> spliterator() {
return new ValueSpliterator<>(HashMap.this, 0, -1, 0, 0);
}
+
+ public Object[] toArray() {
+ return valuesToArray(new Object[size]);
+ }
+
+ public <T> T[] toArray(T[] a) {
+ return valuesToArray(prepareArray(a));
+ }
+
public final void forEach(Consumer<? super V> action) {
Node<K,V>[] tab;
if (action == null)
--- a/src/java.base/share/classes/java/util/HashSet.java Fri Jun 14 20:56:48 2019 -0400
+++ b/src/java.base/share/classes/java/util/HashSet.java Fri Jun 14 21:04:16 2019 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -358,4 +358,14 @@
public Spliterator<E> spliterator() {
return new HashMap.KeySpliterator<>(map, 0, -1, 0, 0);
}
+
+ @Override
+ public Object[] toArray() {
+ return map.keysToArray(new Object[map.size()]);
+ }
+
+ @Override
+ public <T> T[] toArray(T[] a) {
+ return map.keysToArray(map.prepareArray(a));
+ }
}
--- a/src/java.base/share/classes/java/util/LinkedHashMap.java Fri Jun 14 20:56:48 2019 -0400
+++ b/src/java.base/share/classes/java/util/LinkedHashMap.java Fri Jun 14 21:04:16 2019 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -536,6 +536,26 @@
return ks;
}
+ @Override
+ final <T> T[] keysToArray(T[] a) {
+ Object[] r = a;
+ int idx = 0;
+ for (LinkedHashMap.Entry<K,V> e = head; e != null; e = e.after) {
+ r[idx++] = e.key;
+ }
+ return a;
+ }
+
+ @Override
+ final <T> T[] valuesToArray(T[] a) {
+ Object[] r = a;
+ int idx = 0;
+ for (LinkedHashMap.Entry<K,V> e = head; e != null; e = e.after) {
+ r[idx++] = e.value;
+ }
+ return a;
+ }
+
final class LinkedKeySet extends AbstractSet<K> {
public final int size() { return size; }
public final void clear() { LinkedHashMap.this.clear(); }
@@ -551,6 +571,15 @@
Spliterator.ORDERED |
Spliterator.DISTINCT);
}
+
+ public Object[] toArray() {
+ return keysToArray(new Object[size]);
+ }
+
+ public <T> T[] toArray(T[] a) {
+ return keysToArray(prepareArray(a));
+ }
+
public final void forEach(Consumer<? super K> action) {
if (action == null)
throw new NullPointerException();
@@ -600,6 +629,15 @@
return Spliterators.spliterator(this, Spliterator.SIZED |
Spliterator.ORDERED);
}
+
+ public Object[] toArray() {
+ return valuesToArray(new Object[size]);
+ }
+
+ public <T> T[] toArray(T[] a) {
+ return valuesToArray(prepareArray(a));
+ }
+
public final void forEach(Consumer<? super V> action) {
if (action == null)
throw new NullPointerException();
--- a/src/java.net.http/share/classes/jdk/internal/net/http/Http1HeaderParser.java Fri Jun 14 20:56:48 2019 -0400
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/Http1HeaderParser.java Fri Jun 14 21:04:16 2019 -0400
@@ -194,7 +194,15 @@
if (statusLine.length() < 12) {
throw protocolException("Invalid status line: \"%s\"", statusLine);
}
- responseCode = Integer.parseInt(statusLine.substring(9, 12));
+ try {
+ responseCode = Integer.parseInt(statusLine.substring(9, 12));
+ } catch (NumberFormatException nfe) {
+ throw protocolException("Invalid status line: \"%s\"", statusLine);
+ }
+ // response code expected to be a 3-digit integer (RFC-2616, section 6.1.1)
+ if (responseCode < 100) {
+ throw protocolException("Invalid status line: \"%s\"", statusLine);
+ }
state = State.STATUS_LINE_END;
}
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java Fri Jun 14 20:56:48 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java Fri Jun 14 21:04:16 2019 -0400
@@ -2063,7 +2063,8 @@
@DefinedBy(Api.LANGUAGE_MODEL)
public Type getReceiverType() {
- return asType().getReceiverType();
+ Type result = asType().getReceiverType();
+ return (result == null) ? Type.noType : result;
}
@DefinedBy(Api.LANGUAGE_MODEL)
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shenandoah/ShenandoahHeap.java Fri Jun 14 20:56:48 2019 -0400
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shenandoah/ShenandoahHeap.java Fri Jun 14 21:04:16 2019 -0400
@@ -48,7 +48,6 @@
static private CIntegerField logMinObjAlignmentInBytes;
static private long regionPtrFieldSize;
- static private long brookPtrSize;
static {
VM.registerVMInitializedObserver(new Observer() {
public void update(Observable o, Object data) {
@@ -65,7 +64,6 @@
regions = type.getAddressField("_regions");
logMinObjAlignmentInBytes = type.getCIntegerField("_log_min_obj_alignment_in_bytes");
- brookPtrSize = db.lookupIntConstant("HeapWordSize").longValue();
Type regionPtrType = db.lookupType("ShenandoahHeapRegion*");
regionPtrFieldSize = regionPtrType.getSize();
}
@@ -75,11 +73,6 @@
}
@Override
- public long oopOffset() {
- return brookPtrSize;
- }
-
- @Override
public CollectedHeapName kind() {
return CollectedHeapName.SHENANDOAH;
}
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shenandoah/ShenandoahHeapRegion.java Fri Jun 14 20:56:48 2019 -0400
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shenandoah/ShenandoahHeapRegion.java Fri Jun 14 21:04:16 2019 -0400
@@ -184,10 +184,10 @@
if (regionStart == null) {
regionStart = start;
} else {
- regionEnd = start.addOffsetTo(heap.oopOffset() + size);
+ regionEnd = start.addOffsetTo(size);
}
}
- start = start.addOffsetTo(heap.oopOffset() + size);
+ start = start.addOffsetTo(size);
}
if (regionStart != null) {
@@ -201,15 +201,13 @@
}
private boolean hasForwardee(Address rawPtr) {
- // Use Mark as a helper to read forward pointer value.
+ // Forwarding pointer is stored in mark word when it is flagged "marked"
Mark mark = new Mark(rawPtr);
- Address forwardee = mark.valueAsAddress();
- return (forwardee != rawPtr.addOffsetTo(heap.oopOffset()));
+ return mark.isMarked();
}
private long getObjectSize(Address rawPtr) {
- // Dealing with a raw pointer, offsets forward pointer to find real Oop.
- OopHandle handle = rawPtr.addOffsetToAsOopHandle(heap.oopOffset());
+ OopHandle handle = rawPtr.addOffsetToAsOopHandle(0);
Oop obj = null;
try {
--- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/Http1HeaderParserTest.java Fri Jun 14 20:56:48 2019 -0400
+++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/Http1HeaderParserTest.java Fri Jun 14 21:04:16 2019 -0400
@@ -375,6 +375,17 @@
"HTTP/1.1 200OK\r\n\rT",
"HTTP/1.1 200OK\rT",
+
+ "HTTP/1.0 FOO\r\n",
+
+ "HTTP/1.1 BAR\r\n",
+
+ "HTTP/1.1 +99\r\n",
+
+ "HTTP/1.1 -22\r\n",
+
+ "HTTP/1.1 -20 \r\n"
+
};
Arrays.stream(bad).forEach(responses::add);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/HashMap/ToArray.java Fri Jun 14 21:04:16 2019 -0400
@@ -0,0 +1,155 @@
+/*
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.LongStream;
+
+/*
+ * @test
+ * @summary HashMap.toArray() behavior tests
+ * @author tvaleev
+ */
+public class ToArray {
+ public static void main(String[] args) {
+ checkMap(false);
+ checkMap(true);
+ checkSet(false);
+ checkSet(true);
+ }
+
+ private static <T extends Comparable<T>> void checkToArray(String message, T[] expected, Collection<T> collection,
+ boolean ignoreOrder) {
+ if (ignoreOrder) {
+ Arrays.sort(expected);
+ }
+ checkToObjectArray(message, expected, collection, ignoreOrder);
+ checkToTypedArray(message, expected, Arrays.copyOf(expected, 0), collection, ignoreOrder);
+ checkToTypedArray(message, expected, expected.clone(), collection, ignoreOrder);
+ if (expected.length > 0) {
+ T[] biggerArray = Arrays.copyOf(expected, expected.length * 2);
+ System.arraycopy(expected, 0, biggerArray, expected.length, expected.length);
+ checkToTypedArray(message, expected, biggerArray, collection, ignoreOrder);
+ }
+ }
+
+ private static <T extends Comparable<T>> void checkToTypedArray(String message, T[] expected, T[] inputArray,
+ Collection<T> collection, boolean ignoreOrder) {
+ T[] res = collection.toArray(inputArray);
+ if (expected.length <= inputArray.length && res != inputArray) {
+ throw new AssertionError(message + ": not the same array returned");
+ }
+ if (res.getClass() != expected.getClass()) {
+ throw new AssertionError(message + ": wrong class returned: " + res.getClass());
+ }
+ if (res.length < expected.length) {
+ throw new AssertionError(message + ": length is smaller than expected: " + res.length + " < " + expected.length);
+ }
+ if (ignoreOrder) {
+ Arrays.sort(res, 0, Math.min(res.length, expected.length));
+ }
+ if (inputArray.length <= expected.length) {
+ if (!Arrays.equals(res, expected)) {
+ throw new AssertionError(message + ": not equal: " + Arrays.toString(expected) + " != " +
+ Arrays.toString(res));
+ }
+ } else {
+ int mismatch = Arrays.mismatch(expected, res);
+ if (mismatch != expected.length) {
+ throw new AssertionError(message + ": mismatch at " + mismatch);
+ }
+ if (res[expected.length] != null) {
+ throw new AssertionError(message + ": no null at position " + expected.length);
+ }
+ // The tail of bigger array after expected.length position must be untouched
+ mismatch = Arrays
+ .mismatch(expected, 1, expected.length, res, expected.length + 1, res.length);
+ if (mismatch != -1) {
+ throw new AssertionError(message + ": mismatch at " + mismatch);
+ }
+ }
+ }
+
+ private static <T extends Comparable<T>> void checkToObjectArray(String message, T[] expected,
+ Collection<T> collection, boolean ignoreOrder) {
+ Object[] objects = collection.toArray();
+ if (objects.getClass() != Object[].class) {
+ throw new AssertionError(message + ": wrong class returned: " + objects.getClass());
+ }
+ if (ignoreOrder) {
+ Arrays.sort(objects);
+ }
+ int mismatch = Arrays.mismatch(expected, objects);
+ if (mismatch != -1) {
+ throw new AssertionError(message + ": mismatch at " + mismatch);
+ }
+ }
+
+ private static void checkMap(boolean ordered) {
+ Map<String, String> map = ordered ? new LinkedHashMap<>() : new HashMap<>();
+ checkToArray("Empty-keys", new String[0], map.keySet(), !ordered);
+ checkToArray("Empty-values", new String[0], map.values(), !ordered);
+
+ List<String> keys = new ArrayList<>();
+ List<String> values = new ArrayList<>();
+ for (int i = 0; i < 100; i++) {
+ keys.add(String.valueOf(i));
+ values.add(String.valueOf(i * 2));
+ map.put(String.valueOf(i), String.valueOf(i * 2));
+ checkToArray(i + "-keys", keys.toArray(new String[0]), map.keySet(), !ordered);
+ checkToArray(i + "-values", values.toArray(new String[0]), map.values(), !ordered);
+ }
+ map.clear();
+ checkToArray("Empty-keys", new String[0], map.keySet(), !ordered);
+ checkToArray("Empty-values", new String[0], map.values(), !ordered);
+ }
+
+ private static void checkSet(boolean ordered) {
+ Collection<String> set = ordered ? new LinkedHashSet<>() : new HashSet<>();
+ checkToArray("Empty", new String[0], set, !ordered);
+ set.add("foo");
+ checkToArray("One", new String[]{"foo"}, set, !ordered);
+ set.add("bar");
+ checkToArray("Two", new String[]{"foo", "bar"}, set, !ordered);
+
+ Collection<Long> longSet = ordered ? new LinkedHashSet<>() : new HashSet<>();
+ for (int x = 0; x < 100; x++) {
+ longSet.add((long) x);
+ }
+ checkToArray("100", LongStream.range(0, 100).boxed().toArray(Long[]::new), longSet, !ordered);
+ longSet.clear();
+ checkToArray("After clear", new Long[0], longSet, !ordered);
+ for (int x = 0; x < 100; x++) {
+ longSet.add(((long) x) | (((long) x) << 32));
+ }
+ checkToArray("Collisions", LongStream.range(0, 100).mapToObj(x -> x | (x << 32))
+ .toArray(Long[]::new), longSet, !ordered);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/processing/model/element/TestExecutableReceiverType.java Fri Jun 14 21:04:16 2019 -0400
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2013, 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 8222369
+ * @summary Test behavior of ExecutableElement.getReceiverType
+ * @library /tools/javac/lib
+ * @build JavacTestingAbstractProcessor TestExecutableReceiverType
+ * @compile -processor TestExecutableReceiverType -proc:only TestExecutableReceiverType.java
+ */
+
+import java.util.Set;
+import java.lang.annotation.*;
+import javax.annotation.processing.*;
+import javax.lang.model.element.*;
+import javax.lang.model.type.*;
+import javax.lang.model.util.*;
+import static javax.tools.Diagnostic.Kind.*;
+
+/**
+ * Verify that proper type objects are returned from ExecutableElement.getReceiverType
+ */
+public class TestExecutableReceiverType extends JavacTestingAbstractProcessor {
+ public boolean process(Set<? extends TypeElement> annotations,
+ RoundEnvironment roundEnv) {
+ if (!roundEnv.processingOver()) {
+ int count = 0;
+ count += testType(elements.getTypeElement("MethodHost"));
+ count += testType(elements.getTypeElement("MethodHost.Nested"));
+
+ if (count == 0) {
+ messager.printMessage(ERROR, "No executables visited.");
+ }
+ }
+ return true;
+ }
+
+ int testType(TypeElement typeElement) {
+ int count = 0;
+ for (ExecutableElement executable :
+ ElementFilter.constructorsIn(typeElement.getEnclosedElements())) {
+ count += testExecutable(executable);
+ }
+
+ for (ExecutableElement executable :
+ ElementFilter.methodsIn(typeElement.getEnclosedElements())) {
+ count += testExecutable(executable);
+ }
+ return count;
+ }
+
+ int testExecutable(ExecutableElement executable) {
+ TypeKind expectedKind = executable.getAnnotation(ReceiverTypeKind.class).value();
+ TypeKind actualKind = executable.getReceiverType().getKind();
+
+ if (actualKind != expectedKind) {
+ messager.printMessage(ERROR,
+ String.format("Unexpected TypeKind on receiver of %s:" +
+ " expected %s\t got %s%n",
+ executable, expectedKind, actualKind));
+ }
+ return 1;
+ }
+}
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface ReceiverTypeKind {
+ TypeKind value();
+}
+
+/**
+ * Class to host various methods, etc.
+ */
+class MethodHost {
+ @ReceiverTypeKind(TypeKind.NONE)
+ public MethodHost() {}
+
+ @ReceiverTypeKind(TypeKind.NONE)
+ public static void foo() {return;}
+
+ @ReceiverTypeKind(TypeKind.NONE)
+ public void bar() {return;}
+
+ @ReceiverTypeKind(TypeKind.DECLARED)
+ public void quux(MethodHost this) {return;}
+
+ private class Nested {
+ @ReceiverTypeKind(TypeKind.DECLARED)
+ public Nested(MethodHost MethodHost.this) {}
+ }
+}
--- a/test/langtools/tools/javac/sym/ElementStructureTest.java Fri Jun 14 20:56:48 2019 -0400
+++ b/test/langtools/tools/javac/sym/ElementStructureTest.java Fri Jun 14 21:04:16 2019 -0400
@@ -409,7 +409,7 @@
for (VariableElement param : e.getParameters()) {
visit(param, p);
}
- out.write(String.valueOf(e.getReceiverType()));
+ out.write(String.valueOf(typeMirrorTranslate(e.getReceiverType())));
write(e.getReturnType());
out.write(e.getSimpleName().toString());
writeTypes(e.getThrownTypes());
@@ -425,6 +425,18 @@
return null;
}
+ /**
+ * Original implementation of getReceiverType returned null
+ * for many cases where TypeKind.NONE was specified; translate
+ * back to null to compare against old hashes.
+ */
+ private TypeMirror typeMirrorTranslate(TypeMirror type) {
+ if (type.getKind() == javax.lang.model.type.TypeKind.NONE)
+ return null;
+ else
+ return type;
+ }
+
@Override
public Void visitPackage(PackageElement e, Void p) {
List<Element> types = new ArrayList<>(e.getEnclosedElements());
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/micro/org/openjdk/bench/java/util/HashMapToArray.java Fri Jun 14 21:04:16 2019 -0400
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+package org.openjdk.bench.java.util;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Param;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
+@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
+@Fork(3)
+@State(Scope.Thread)
+public class HashMapToArray {
+
+ @Param({"0", "1", "10", "1000", "100000"})
+ public int size;
+
+ @Param({"HashMap", "LinkedHashMap"})
+ public String mapType;
+
+ private Map<Integer, Integer> map;
+
+ @Setup
+ public void setup() {
+ switch (mapType) {
+ case "HashMap":
+ map = new HashMap<>();
+ break;
+ case "LinkedHashMap":
+ map = new LinkedHashMap<>();
+ break;
+ default:
+ throw new IllegalStateException();
+ }
+ for (int i = 0; i < size; i++) {
+ map.put(i, i * i);
+ }
+ }
+
+ @Benchmark
+ public Object[] testKeySetToArray() {
+ return map.keySet().toArray();
+ }
+
+ @Benchmark
+ public Object[] testKeySetToArrayTyped() {
+ return map.keySet().toArray(new Integer[0]);
+ }
+
+ @Benchmark
+ public Object[] testValuesToArray() {
+ return map.values().toArray();
+ }
+
+ @Benchmark
+ public Object[] testValuesToArrayTyped() {
+ return map.values().toArray(new Integer[0]);
+ }
+}