This commit is contained in:
Jesper Wilhelmsson 2021-06-27 23:51:05 +00:00
commit a29953d805
90 changed files with 1714 additions and 489 deletions
.github/workflows
src
hotspot
java.base
share/classes
unix/native/libnio/fs
java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile
jdk.compiler/share/classes/com/sun/tools/javac
jdk.incubator.vector/share/classes/jdk/incubator/vector
jdk.javadoc/share/classes/jdk/javadoc/doclet
jdk.jpackage
macosx/classes/jdk/jpackage/internal
share/classes/jdk/jpackage/internal
test
hotspot/jtreg
ProblemList-Xcomp.txtProblemList-zgc.txtProblemList.txtTEST.groups
compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/aarch64
vmTestbase/nsk/share/jpda
jaxp/javax/xml/jaxp/unittest/bcel
jdk
langtools/tools/javac

@ -172,7 +172,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install gcc-10=10.2.0-5ubuntu1~20.04 g++-10=10.2.0-5ubuntu1~20.04 libxrandr-dev libxtst-dev libcups2-dev libasound2-dev
sudo apt-get install gcc-10=10.3.0-1ubuntu1~20.04 g++-10=10.3.0-1ubuntu1~20.04 libxrandr-dev libxtst-dev libcups2-dev libasound2-dev
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10
- name: Configure
@ -487,12 +487,12 @@ jobs:
- name: Install native host dependencies
run: |
sudo apt-get install gcc-10=10.2.0-5ubuntu1~20.04 g++-10=10.2.0-5ubuntu1~20.04 libxrandr-dev libxtst-dev libcups2-dev libasound2-dev
sudo apt-get install gcc-10=10.3.0-1ubuntu1~20.04 g++-10=10.3.0-1ubuntu1~20.04 libxrandr-dev libxtst-dev libcups2-dev libasound2-dev
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10
if: matrix.debian-arch == ''
- name: Install cross-compilation host dependencies
run: sudo apt-get install gcc-10-${{ matrix.gnu-arch }}-linux-gnu${{ matrix.gnu-flavor}}=10.2.0-5ubuntu1~20.04cross1 g++-10-${{ matrix.gnu-arch }}-linux-gnu${{ matrix.gnu-flavor}}=10.2.0-5ubuntu1~20.04cross1
run: sudo apt-get install gcc-10-${{ matrix.gnu-arch }}-linux-gnu${{ matrix.gnu-flavor}}=10.3.0-1ubuntu1~20.04cross1 g++-10-${{ matrix.gnu-arch }}-linux-gnu${{ matrix.gnu-flavor}}=10.3.0-1ubuntu1~20.04cross1
if: matrix.debian-arch != ''
- name: Cache sysroot

@ -39,6 +39,7 @@
#include "oops/objArrayKlass.hpp"
#include "oops/oop.inline.hpp"
#include "prims/methodHandles.hpp"
#include "runtime/arguments.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/sharedRuntime.hpp"
@ -7657,7 +7658,10 @@ address generate_avx_ghash_processBlocks() {
// Get svml stub routine addresses
void *libsvml = NULL;
char ebuf[1024];
libsvml = os::dll_load(JNI_LIB_PREFIX "svml" JNI_LIB_SUFFIX, ebuf, sizeof ebuf);
char dll_name[JVM_MAXPATHLEN];
if (os::dll_locate_lib(dll_name, sizeof(dll_name), Arguments::get_dll_dir(), "svml")) {
libsvml = os::dll_load(dll_name, ebuf, sizeof ebuf);
}
if (libsvml != NULL) {
// SVML method naming convention
// All the methods are named as __svml_op<T><N>_ha_<VV>

@ -8062,7 +8062,7 @@ instruct vpternlog(vec dst, vec src2, vec src3, immU8 func) %{
%}
instruct vpternlog_mem(vec dst, vec src2, memory src3, immU8 func) %{
predicate(vector_length_in_bytes(n->in(1)) > 8);
predicate(vector_length_in_bytes(n->in(1)->in(1)) > 8);
match(Set dst (MacroLogicV (Binary dst src2) (Binary (LoadVector src3) func)));
effect(TEMP dst);
format %{ "vpternlogd $dst,$src2,$src3,$func\t! vector ternary logic" %}

@ -194,11 +194,21 @@ int ZBarrierSetC2::estimate_stub_size() const {
static void set_barrier_data(C2Access& access) {
if (ZBarrierSet::barrier_needed(access.decorators(), access.type())) {
if (access.decorators() & ON_WEAK_OOP_REF) {
access.set_barrier_data(ZLoadBarrierWeak);
uint8_t barrier_data = 0;
if (access.decorators() & ON_PHANTOM_OOP_REF) {
barrier_data |= ZLoadBarrierPhantom;
} else if (access.decorators() & ON_WEAK_OOP_REF) {
barrier_data |= ZLoadBarrierWeak;
} else {
access.set_barrier_data(ZLoadBarrierStrong);
barrier_data |= ZLoadBarrierStrong;
}
if (access.decorators() & AS_NO_KEEPALIVE) {
barrier_data |= ZLoadBarrierNoKeepalive;
}
access.set_barrier_data(barrier_data);
}
}

@ -67,7 +67,7 @@ static const size_t ELEMENT_SIZE = sizeof(JfrEpochQueueKlassElement);
static const size_t NARROW_ELEMENT_SIZE = sizeof(JfrEpochQueueNarrowKlassElement);
static const size_t THRESHOLD_SHIFT = 30;
// If the upshifted traceid value is less than this threshold (1 073 741 824),
// If the traceid value is less than this threshold (1 073 741 824),
// compress the element for more effective queue storage.
static const traceid uncompressed_threshold = ((traceid)1) << THRESHOLD_SHIFT;
@ -121,30 +121,36 @@ static traceid read_element(const u1* pos, const Klass** klass, bool compressed)
return compressed ? read_compressed_element(pos, klass) : read_uncompressed_element(pos, klass);
}
template <typename T>
static inline void store_traceid(T* element, traceid id, bool uncompressed) {
#ifdef VM_LITTLE_ENDIAN
id <<= METADATA_SHIFT;
#endif
element->id = uncompressed ? id | UNCOMPRESSED : id;
}
static void store_compressed_element(traceid id, const Klass* klass, u1* pos) {
assert(can_compress_element(id), "invariant");
JfrEpochQueueNarrowKlassElement* const element = new (pos) JfrEpochQueueNarrowKlassElement();
element->id = id;
store_traceid(element, id, false);
element->compressed_klass = encode(klass);
}
static void store_uncompressed_element(traceid id, const Klass* klass, u1* pos) {
JfrEpochQueueKlassElement* const element = new (pos) JfrEpochQueueKlassElement();
element->id = id | UNCOMPRESSED;
store_traceid(element, id, true);
element->klass = klass;
}
static void store_element(const Klass* klass, u1* pos) {
assert(pos != NULL, "invariant");
assert(klass != NULL, "invariant");
traceid id = JfrTraceId::load_raw(klass);
#ifdef VM_LITTLE_ENDIAN
id <<= METADATA_SHIFT;
#endif
const traceid id = JfrTraceId::load_raw(klass);
if (can_compress_element(id)) {
store_compressed_element(id, klass, pos);
} else {
store_uncompressed_element(id, klass, pos);
return;
}
store_uncompressed_element(id, klass, pos);
}
static void set_unloaded(const u1* pos) {

@ -68,7 +68,7 @@ JfrEpochQueue<ElementPolicy>::storage_for_element(JfrEpochQueue<ElementPolicy>::
template <template <typename> class ElementPolicy>
void JfrEpochQueue<ElementPolicy>::enqueue(JfrEpochQueue<ElementPolicy>::TypePtr t) {
assert(t != NULL, "invariant");
static size_t element_size = _policy.element_size(t);
size_t element_size = _policy.element_size(t);
BufferPtr buffer = storage_for_element(t, element_size);
assert(buffer != NULL, "invariant");
_policy.store_element(t, buffer);

@ -46,6 +46,7 @@ void AsyncLogWriter::enqueue_locked(const AsyncLogMessage& msg) {
uint32_t* counter = _stats.add_if_absent(msg.output(), 0, &p_created);
*counter = *counter + 1;
// drop the enqueueing message.
os::free(msg.message());
return;
}

@ -1032,6 +1032,11 @@ bool LibraryCallKit::inline_preconditions_checkIndex(BasicType bt) {
Deoptimization::Action_make_not_entrant);
}
if (stopped()) {
// Length is known to be always negative during compilation and the IR graph so far constructed is good so return success
return true;
}
// length is now known postive, add a cast node to make this explicit
jlong upper_bound = _gvn.type(length)->is_integer(bt)->hi_as_long();
Node* casted_length = ConstraintCastNode::make(control(), length, TypeInteger::make(0, upper_bound, Type::WidenMax, bt), bt);
@ -1039,10 +1044,6 @@ bool LibraryCallKit::inline_preconditions_checkIndex(BasicType bt) {
replace_in_map(length, casted_length);
length = casted_length;
if (stopped()) {
return false;
}
// Use an unsigned comparison for the range check itself
Node* rc_cmp = _gvn.transform(CmpNode::make(index, length, bt, true));
BoolTest::mask btest = BoolTest::lt;
@ -1061,7 +1062,8 @@ bool LibraryCallKit::inline_preconditions_checkIndex(BasicType bt) {
}
if (stopped()) {
return false;
// Range check is known to always fail during compilation and the IR graph so far constructed is good so return success
return true;
}
// index is now known to be >= 0 and < length, cast it
@ -5343,12 +5345,11 @@ bool LibraryCallKit::inline_vectorizedMismatch() {
if (do_partial_inline) {
assert(elem_bt != T_ILLEGAL, "sanity");
const TypeVect* vt = TypeVect::make(elem_bt, inline_limit);
if (Matcher::match_rule_supported_vector(Op_VectorMaskGen, inline_limit, elem_bt) &&
Matcher::match_rule_supported_vector(Op_LoadVectorMasked, inline_limit, elem_bt) &&
Matcher::match_rule_supported_vector(Op_VectorCmpMasked, inline_limit, elem_bt)) {
const TypeVect* vt = TypeVect::make(elem_bt, inline_limit);
Node* cmp_length = _gvn.transform(new CmpINode(length, intcon(inline_limit)));
Node* bol_gt = _gvn.transform(new BoolNode(cmp_length, BoolTest::gt));

@ -1197,11 +1197,6 @@ JavaThread::~JavaThread() {
#if INCLUDE_JVMCI
if (JVMCICounterSize > 0) {
if (jvmci_counters_include(this)) {
for (int i = 0; i < JVMCICounterSize; i++) {
_jvmci_old_thread_counters[i] += _jvmci_counters[i];
}
}
FREE_C_HEAP_ARRAY(jlong, _jvmci_counters);
}
#endif // INCLUDE_JVMCI
@ -1457,6 +1452,17 @@ void JavaThread::exit(bool destroy_vm, ExitType exit_type) {
_timer_exit_phase3.stop();
_timer_exit_phase4.start();
}
#if INCLUDE_JVMCI
if (JVMCICounterSize > 0) {
if (jvmci_counters_include(this)) {
for (int i = 0; i < JVMCICounterSize; i++) {
_jvmci_old_thread_counters[i] += _jvmci_counters[i];
}
}
}
#endif // INCLUDE_JVMCI
// Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread
Threads::remove(this, daemon);

@ -894,7 +894,7 @@ abstract class GaloisCounterMode extends CipherSpi {
// if src is read only, then we need a copy
if (!src.isReadOnly()) {
// If using the heap, check underlying byte[] address.
if (!src.array().equals(dst.array()) ) {
if (src.array() != dst.array()) {
return dst;
}

@ -59,7 +59,8 @@ public class MethodHandleProxies {
* even though it re-declares the {@code Object.equals} method and also
* declares default methods, such as {@code Comparator.reverse}.
* <p>
* The interface must be public. No additional access checks are performed.
* The interface must be public and not {@linkplain Class#isSealed() sealed}.
* No additional access checks are performed.
* <p>
* The resulting instance of the required type will respond to
* invocation of the type's uniquely named method by calling
@ -156,6 +157,8 @@ public class MethodHandleProxies {
public static <T> T asInterfaceInstance(final Class<T> intfc, final MethodHandle target) {
if (!intfc.isInterface() || !Modifier.isPublic(intfc.getModifiers()))
throw newIllegalArgumentException("not a public interface", intfc.getName());
if (intfc.isSealed())
throw newIllegalArgumentException("a sealed interface", intfc.getName());
final MethodHandle mh;
if (System.getSecurityManager() != null) {
final Class<?> caller = Reflection.getCallerClass();

@ -2768,6 +2768,7 @@ assertEquals("[x, y, z]", pb.command().toString());
* @throws ClassNotFoundException if the class cannot be loaded by the lookup class' loader.
* @throws IllegalAccessException if the class is not accessible, using the allowed access
* modes.
* @throws NullPointerException if {@code targetName} is null
* @since 9
* @jvms 5.4.3.1 Class and Interface Resolution
*/
@ -2837,8 +2838,12 @@ assertEquals("[x, y, z]", pb.command().toString());
/**
* Determines if a class can be accessed from the lookup context defined by
* this {@code Lookup} object. The static initializer of the class is not run.
* If {@code targetClass} is an array class, {@code targetClass} is accessible
* if the element type of the array class is accessible. Otherwise,
* {@code targetClass} is determined as accessible as follows.
*
* <p>
* If the {@code targetClass} is in the same module as the lookup class,
* If {@code targetClass} is in the same module as the lookup class,
* the lookup class is {@code LC} in module {@code M1} and
* the previous lookup class is in module {@code M0} or
* {@code null} if not present,
@ -2861,7 +2866,7 @@ assertEquals("[x, y, z]", pb.command().toString());
* can access public types in all modules when the type is in a package
* that is exported unconditionally.
* <p>
* Otherwise, the target class is in a different module from {@code lookupClass},
* Otherwise, {@code targetClass} is in a different module from {@code lookupClass},
* and if this lookup does not have {@code PUBLIC} access, {@code lookupClass}
* is inaccessible.
* <p>
@ -2897,13 +2902,14 @@ assertEquals("[x, y, z]", pb.command().toString());
* @return the class that has been access-checked
* @throws IllegalAccessException if the class is not accessible from the lookup class
* and previous lookup class, if present, using the allowed access modes.
* @throws SecurityException if a security manager is present and it
* <a href="MethodHandles.Lookup.html#secmgr">refuses access</a>
* @throws SecurityException if a security manager is present and it
* <a href="MethodHandles.Lookup.html#secmgr">refuses access</a>
* @throws NullPointerException if {@code targetClass} is {@code null}
* @since 9
* @see <a href="#cross-module-lookup">Cross-module lookups</a>
*/
public Class<?> accessClass(Class<?> targetClass) throws IllegalAccessException {
if (!VerifyAccess.isClassAccessible(targetClass, lookupClass, prevLookupClass, allowedModes)) {
if (!isClassAccessible(targetClass)) {
throw makeAccessException(targetClass);
}
checkSecurityManager(targetClass);
@ -3684,7 +3690,11 @@ return mh1;
boolean isClassAccessible(Class<?> refc) {
Objects.requireNonNull(refc);
Class<?> caller = lookupClassOrNull();
return caller == null || VerifyAccess.isClassAccessible(refc, caller, prevLookupClass, allowedModes);
Class<?> type = refc;
while (type.isArray()) {
type = type.getComponentType();
}
return caller == null || VerifyAccess.isClassAccessible(type, caller, prevLookupClass, allowedModes);
}
/** Check name for an illegal leading "&lt;" character. */

@ -710,6 +710,10 @@ public class Proxy implements java.io.Serializable {
throw new IllegalArgumentException(intf.getName() + " is a hidden interface");
}
if (intf.isSealed()) {
throw new IllegalArgumentException(intf.getName() + " is a sealed interface");
}
/*
* Verify that the class loader resolves the name of this
* interface to the same Class object.
@ -930,7 +934,8 @@ public class Proxy implements java.io.Serializable {
* if any of the following restrictions is violated:</a>
* <ul>
* <li>All of {@code Class} objects in the given {@code interfaces} array
* must represent {@linkplain Class#isHidden() non-hidden} interfaces,
* must represent {@linkplain Class#isHidden() non-hidden} and
* {@linkplain Class#isSealed() non-sealed} interfaces,
* not classes or primitive types.
*
* <li>No two elements in the {@code interfaces} array may

@ -31,10 +31,15 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.ref.Reference;
import java.io.FileDescriptor;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import jdk.internal.access.JavaNioAccess;
import jdk.internal.access.SharedSecrets;
import jdk.internal.access.foreign.MemorySegmentProxy;
import jdk.internal.util.ArraysSupport;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.vector.VectorSupport;
/**
@ -334,6 +339,126 @@ public class ScopedMemoryAccess {
Reference.reachabilityFence(scope);
}
}
// ByteBuffer vector access ops
// Buffer access constants, to be initalized when required.
// Avoids a null value for NIO_ACCESS, due to class initalization dependencies
static final class BufferAccess {
// Buffer.address
static final long BUFFER_ADDRESS
= UNSAFE.objectFieldOffset(Buffer.class, "address");
// ByteBuffer.hb
static final long BYTE_BUFFER_HB
= UNSAFE.objectFieldOffset(ByteBuffer.class, "hb");
@ForceInline
static Object bufferBase(ByteBuffer bb) {
return UNSAFE.getReference(bb, BYTE_BUFFER_HB);
}
@ForceInline
static long bufferAddress(ByteBuffer bb, long offset) {
return UNSAFE.getLong(bb, BUFFER_ADDRESS) + offset;
}
static final JavaNioAccess NIO_ACCESS = SharedSecrets.getJavaNioAccess();
@ForceInline
static ScopedMemoryAccess.Scope scope(ByteBuffer bb) {
MemorySegmentProxy segmentProxy = NIO_ACCESS.bufferSegment(bb);
return segmentProxy != null ?
segmentProxy.scope() : null;
}
}
@ForceInline
public static
<V extends VectorSupport.Vector<E>, E, S extends VectorSupport.VectorSpecies<E>>
V loadFromByteBuffer(Class<? extends V> vmClass, Class<E> e, int length,
ByteBuffer bb, int offset,
S s,
VectorSupport.LoadOperation<ByteBuffer, V, E, S> defaultImpl) {
try {
return loadFromByteBufferScoped(
BufferAccess.scope(bb),
vmClass, e, length,
bb, offset,
s,
defaultImpl);
} catch (ScopedMemoryAccess.Scope.ScopedAccessError ex) {
throw new IllegalStateException("This segment is already closed");
}
}
@Scoped
@ForceInline
private static
<V extends VectorSupport.Vector<E>, E, S extends VectorSupport.VectorSpecies<E>>
V loadFromByteBufferScoped(ScopedMemoryAccess.Scope scope,
Class<? extends V> vmClass, Class<E> e, int length,
ByteBuffer bb, int offset,
S s,
VectorSupport.LoadOperation<ByteBuffer, V, E, S> defaultImpl) {
try {
if (scope != null) {
scope.checkValidState();
}
return VectorSupport.load(vmClass, e, length,
BufferAccess.bufferBase(bb), BufferAccess.bufferAddress(bb, offset),
bb, offset, s,
defaultImpl);
} finally {
Reference.reachabilityFence(scope);
}
}
@ForceInline
public static
<V extends VectorSupport.Vector<E>, E>
void storeIntoByteBuffer(Class<? extends V> vmClass, Class<E> e, int length,
V v,
ByteBuffer bb, int offset,
VectorSupport.StoreVectorOperation<ByteBuffer, V> defaultImpl) {
try {
storeIntoByteBufferScoped(
BufferAccess.scope(bb),
vmClass, e, length,
v,
bb, offset,
defaultImpl);
} catch (ScopedMemoryAccess.Scope.ScopedAccessError ex) {
throw new IllegalStateException("This segment is already closed");
}
}
@Scoped
@ForceInline
private static
<V extends VectorSupport.Vector<E>, E>
void storeIntoByteBufferScoped(ScopedMemoryAccess.Scope scope,
Class<? extends V> vmClass, Class<E> e, int length,
V v,
ByteBuffer bb, int offset,
VectorSupport.StoreVectorOperation<ByteBuffer, V> defaultImpl) {
try {
if (scope != null) {
scope.checkValidState();
}
VectorSupport.store(vmClass, e, length,
BufferAccess.bufferBase(bb), BufferAccess.bufferAddress(bb, offset),
v,
bb, offset,
defaultImpl);
} finally {
Reference.reachabilityFence(scope);
}
}
// typed-ops here
// Note: all the accessor methods defined below take advantage of argument type profiling

@ -68,53 +68,9 @@ int fcopyfile_callback(int what, int stage, copyfile_state_t state,
}
#endif
/**
* Transfer all bytes from src to dst within the kernel if possible (Linux),
* otherwise via user-space buffers
*/
JNIEXPORT void JNICALL
Java_sun_nio_fs_UnixCopyFile_transfer
(JNIEnv* env, jclass this, jint dst, jint src, jlong cancelAddress)
// Transfer via user-space buffers
void transfer(JNIEnv* env, jint dst, jint src, volatile jint* cancel)
{
volatile jint* cancel = (jint*)jlong_to_ptr(cancelAddress);
#if defined(__linux__)
// Transfer within the kernel
const size_t count = cancel != NULL ?
1048576 : // 1 MB to give cancellation a chance
0x7ffff000; // maximum number of bytes that sendfile() can transfer
ssize_t bytes_sent;
do {
RESTARTABLE(sendfile64(dst, src, NULL, count), bytes_sent);
if (bytes_sent == -1) {
throwUnixException(env, errno);
return;
}
if (cancel != NULL && *cancel != 0) {
throwUnixException(env, ECANCELED);
return;
}
} while (bytes_sent > 0);
#elif defined(_ALLBSD_SOURCE)
copyfile_state_t state;
if (cancel != NULL) {
state = copyfile_state_alloc();
copyfile_state_set(state, COPYFILE_STATE_STATUS_CB, fcopyfile_callback);
copyfile_state_set(state, COPYFILE_STATE_STATUS_CTX, (void*)cancel);
} else {
state = NULL;
}
if (fcopyfile(src, dst, state, COPYFILE_DATA) < 0) {
int errno_fcopyfile = errno;
if (state != NULL)
copyfile_state_free(state);
throwUnixException(env, errno_fcopyfile);
return;
}
if (state != NULL)
copyfile_state_free(state);
#else
// Transfer via user-space buffers
char buf[8192];
for (;;) {
@ -143,5 +99,59 @@ Java_sun_nio_fs_UnixCopyFile_transfer
len -= n;
} while (len > 0);
}
}
/**
* Transfer all bytes from src to dst within the kernel if possible (Linux),
* otherwise via user-space buffers
*/
JNIEXPORT void JNICALL
Java_sun_nio_fs_UnixCopyFile_transfer
(JNIEnv* env, jclass this, jint dst, jint src, jlong cancelAddress)
{
volatile jint* cancel = (jint*)jlong_to_ptr(cancelAddress);
#if defined(__linux__)
// Transfer within the kernel
const size_t count = cancel != NULL ?
1048576 : // 1 MB to give cancellation a chance
0x7ffff000; // maximum number of bytes that sendfile() can transfer
ssize_t bytes_sent;
do {
RESTARTABLE(sendfile64(dst, src, NULL, count), bytes_sent);
if (bytes_sent == -1) {
if (errno == EINVAL || errno == ENOSYS) {
// Fall back to copying via user-space buffers
transfer(env, dst, src, cancel);
} else {
throwUnixException(env, errno);
}
return;
}
if (cancel != NULL && *cancel != 0) {
throwUnixException(env, ECANCELED);
return;
}
} while (bytes_sent > 0);
#elif defined(_ALLBSD_SOURCE)
copyfile_state_t state;
if (cancel != NULL) {
state = copyfile_state_alloc();
copyfile_state_set(state, COPYFILE_STATE_STATUS_CB, fcopyfile_callback);
copyfile_state_set(state, COPYFILE_STATE_STATUS_CTX, (void*)cancel);
} else {
state = NULL;
}
if (fcopyfile(src, dst, state, COPYFILE_DATA) < 0) {
int errno_fcopyfile = errno;
if (state != NULL)
copyfile_state_free(state);
throwUnixException(env, errno_fcopyfile);
return;
}
if (state != NULL)
copyfile_state_free(state);
#else
transfer(env, dst, src, cancel);
#endif
}

@ -42,7 +42,7 @@ import com.sun.org.apache.bcel.internal.util.ByteSequence;
/**
* Utility functions that do not really belong to any class in particular.
*
* @LastModified: May 2021
* @LastModified: June 2021
*/
// @since 6.0 methods are no longer final
public abstract class Utility {
@ -1461,6 +1461,7 @@ public abstract class Utility {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gos = new GZIPOutputStream(baos)) {
gos.write(bytes, 0, bytes.length);
gos.finish();
bytes = baos.toByteArray();
}
}

@ -4064,24 +4064,19 @@ public class Attr extends JCTree.Visitor {
tree.expr.pos(), attribExpr(tree.expr, env));
Type clazztype;
JCTree typeTree;
boolean checkRawTypes;
if (tree.pattern.getTag() == BINDINGPATTERN) {
if (tree.pattern.getTag() == BINDINGPATTERN ||
tree.pattern.getTag() == PARENTHESIZEDPATTERN) {
attribTree(tree.pattern, env, unknownExprInfo);
clazztype = tree.pattern.type;
if (types.isSubtype(exprtype, clazztype) &&
!exprtype.isErroneous() && !clazztype.isErroneous()) {
log.error(tree.pos(), Errors.InstanceofPatternNoSubtype(exprtype, clazztype));
}
JCBindingPattern pattern = (JCBindingPattern) tree.pattern;
typeTree = pattern.var.vartype;
if (!clazztype.hasTag(TYPEVAR)) {
clazztype = chk.checkClassOrArrayType(pattern.var.vartype.pos(), clazztype);
}
checkRawTypes = true;
typeTree = TreeInfo.primaryPatternTree((JCPattern) tree.pattern).var.vartype;
} else {
clazztype = attribType(tree.pattern, env);
typeTree = tree.pattern;
checkRawTypes = false;
chk.validate(typeTree, env, false);
}
if (!clazztype.hasTag(TYPEVAR)) {
clazztype = chk.checkClassOrArrayType(typeTree.pos(), clazztype);
@ -4099,7 +4094,6 @@ public class Attr extends JCTree.Visitor {
clazztype = types.createErrorType(clazztype);
}
}
chk.validate(typeTree, env, checkRawTypes);
chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
result = check(tree, syms.booleanType, KindSelector.VAL, resultInfo);
}
@ -4133,6 +4127,7 @@ public class Attr extends JCTree.Visitor {
annotate.annotateLater(tree.var.mods.annotations, env, v, tree.pos());
annotate.queueScanTreeAndTypeAnnotate(tree.var.vartype, env, v, tree.var.pos());
annotate.flush();
chk.validate(tree.var.vartype, env, true);
result = tree.type;
matchBindings = new MatchBindings(List.of(v), List.nil());
}
@ -4140,6 +4135,7 @@ public class Attr extends JCTree.Visitor {
@Override
public void visitParenthesizedPattern(JCParenthesizedPattern tree) {
attribExpr(tree.pattern, env);
result = tree.type = tree.pattern.type;
}
@Override

@ -1217,6 +1217,7 @@ public class DeferredAttr extends JCTree.Visitor {
freeArgVars.nonEmpty()) {
stuckVars.addAll(freeArgVars);
depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType()));
depVars.addAll(inferenceContext.freeVarsIn(descType.getThrownTypes()));
}
scanLambdaBody(tree, descType.getReturnType());
}
@ -1238,6 +1239,7 @@ public class DeferredAttr extends JCTree.Visitor {
tree.getOverloadKind() != JCMemberReference.OverloadKind.UNOVERLOADED) {
stuckVars.addAll(freeArgVars);
depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType()));
depVars.addAll(inferenceContext.freeVarsIn(descType.getThrownTypes()));
}
}

@ -30,7 +30,7 @@ package com.sun.tools.javac.comp;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.StreamSupport;
import com.sun.source.tree.LambdaExpressionTree.BodyKind;
import com.sun.tools.javac.code.*;
@ -45,17 +45,16 @@ import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.JCDiagnostic.Error;
import com.sun.tools.javac.util.JCDiagnostic.Warning;
import com.sun.tools.javac.code.Kinds.Kind;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.tree.JCTree.*;
import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Flags.BLOCK;
import static com.sun.tools.javac.code.Kinds.Kind.*;
import com.sun.tools.javac.code.Type.TypeVar;
import static com.sun.tools.javac.code.TypeTag.BOOLEAN;
import static com.sun.tools.javac.code.TypeTag.VOID;
import com.sun.tools.javac.resources.CompilerProperties.Fragments;
import com.sun.tools.javac.tree.JCTree.JCParenthesizedPattern;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
import com.sun.tools.javac.util.JCDiagnostic.Fragment;
@ -665,7 +664,7 @@ public class Flow {
ListBuffer<PendingExit> prevPendingExits = pendingExits;
pendingExits = new ListBuffer<>();
scan(tree.selector);
Set<Object> constants = tree.patternSwitch ? allSwitchConstants(tree.selector) : null;
Set<Symbol> constants = tree.patternSwitch ? new HashSet<>() : null;
for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) {
alive = Liveness.ALIVE;
JCCase c = l.head;
@ -687,8 +686,9 @@ public class Flow {
l.tail.head.pos(),
Warnings.PossibleFallThroughIntoCase);
}
if ((constants == null || !constants.isEmpty()) && !tree.hasTotalPattern &&
tree.patternSwitch && !TreeInfo.isErrorEnumSwitch(tree.selector, tree.cases)) {
if (!tree.hasTotalPattern && tree.patternSwitch &&
!TreeInfo.isErrorEnumSwitch(tree.selector, tree.cases) &&
(constants == null || !isExhaustive(tree.selector.type, constants))) {
log.error(tree, Errors.NotExhaustiveStatement);
}
if (!tree.hasTotalPattern) {
@ -702,7 +702,7 @@ public class Flow {
ListBuffer<PendingExit> prevPendingExits = pendingExits;
pendingExits = new ListBuffer<>();
scan(tree.selector);
Set<Object> constants = allSwitchConstants(tree.selector);
Set<Symbol> constants = new HashSet<>();
Liveness prevAlive = alive;
for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) {
alive = Liveness.ALIVE;
@ -723,47 +723,83 @@ public class Flow {
}
c.completesNormally = alive != Liveness.DEAD;
}
if ((constants == null || !constants.isEmpty()) && !tree.hasTotalPattern &&
!TreeInfo.isErrorEnumSwitch(tree.selector, tree.cases)) {
if (!tree.hasTotalPattern && !TreeInfo.isErrorEnumSwitch(tree.selector, tree.cases) &&
!isExhaustive(tree.selector.type, constants)) {
log.error(tree, Errors.NotExhaustive);
}
alive = prevAlive;
alive = alive.or(resolveYields(tree, prevPendingExits));
}
private Set<Object> allSwitchConstants(JCExpression selector) {
Set<Object> constants = null;
TypeSymbol selectorSym = selector.type.tsym;
if ((selectorSym.flags() & ENUM) != 0) {
constants = new HashSet<>();
Predicate<Symbol> enumConstantFilter =
s -> (s.flags() & ENUM) != 0 && s.kind == Kind.VAR;
for (Symbol s : selectorSym.members().getSymbols(enumConstantFilter)) {
constants.add(s.name);
}
} else if (selectorSym.isAbstract() && selectorSym.isSealed() && selectorSym.kind == Kind.TYP) {
constants = new HashSet<>();
constants.addAll(((ClassSymbol) selectorSym).permitted);
}
return constants;
}
private void handleConstantCaseLabel(Set<Object> constants, JCCaseLabel pat) {
private void handleConstantCaseLabel(Set<Symbol> constants, JCCaseLabel pat) {
if (constants != null) {
if (pat.isExpression()) {
JCExpression expr = (JCExpression) pat;
if (expr.hasTag(IDENT))
constants.remove(((JCIdent) expr).name);
if (expr.hasTag(IDENT) && ((JCIdent) expr).sym.isEnum())
constants.add(((JCIdent) expr).sym);
} else if (pat.isPattern()) {
PatternPrimaryType patternType = TreeInfo.primaryPatternType((JCPattern) pat);
if (patternType.unconditional()) {
constants.remove(patternType.type().tsym);
constants.add(patternType.type().tsym);
}
}
}
}
private void transitiveCovers(Set<Symbol> covered) {
List<Symbol> todo = List.from(covered);
while (todo.nonEmpty()) {
Symbol sym = todo.head;
todo = todo.tail;
switch (sym.kind) {
case VAR -> {
Iterable<Symbol> constants = sym.owner
.members()
.getSymbols(s -> s.isEnum() &&
s.kind == VAR);
boolean hasAll = StreamSupport.stream(constants.spliterator(), false)
.allMatch(covered::contains);
if (hasAll && covered.add(sym.owner)) {
todo = todo.prepend(sym.owner);
}
}
case TYP -> {
for (Type sup : types.directSupertypes(sym.type)) {
if (sup.tsym.kind == TYP && sup.tsym.isAbstract() && sup.tsym.isSealed()) {
boolean hasAll = ((ClassSymbol) sup.tsym).permitted
.stream()
.allMatch(covered::contains);
if (hasAll && covered.add(sup.tsym)) {
todo = todo.prepend(sup.tsym);
}
}
}
}
}
}
}
private boolean isExhaustive(Type seltype, Set<Symbol> covered) {
transitiveCovers(covered);
return switch (seltype.getTag()) {
case CLASS -> {
if (seltype.isCompound()) {
if (seltype.isIntersection()) {
yield ((Type.IntersectionClassType) seltype).getComponents().stream().anyMatch(t -> isExhaustive(t, covered));
}
yield false;
}
yield covered.contains(seltype.tsym);
}
case TYPEVAR -> isExhaustive(((TypeVar) seltype).getUpperBound(), covered);
default -> false;
};
}
public void visitTry(JCTry tree) {
ListBuffer<PendingExit> prevPendingExits = pendingExits;
pendingExits = new ListBuffer<>();

@ -186,12 +186,14 @@ public class TransPatterns extends TreeTranslator {
//=>
//(let T' N$temp = E; N$temp instanceof typeof($pattern) && <desugared $pattern>)
//note the pattern desugaring performs binding variable assignments
Symbol exprSym = TreeInfo.symbol(tree.expr);
Type tempType = tree.expr.type.hasTag(BOT) ?
syms.objectType
: tree.expr.type;
VarSymbol prevCurrentValue = currentValue;
try {
JCExpression translatedExpr = translate(tree.expr);
Symbol exprSym = TreeInfo.symbol(translatedExpr);
if (exprSym != null &&
exprSym.kind == Kind.VAR &&
exprSym.owner.kind.matches(Kinds.KindSelector.VAL_MTH)) {
@ -203,7 +205,6 @@ public class TransPatterns extends TreeTranslator {
currentMethodSym);
}
JCExpression translatedExpr = translate(tree.expr);
Type principalType = principalType((JCPattern) tree.pattern);
result = makeBinary(Tag.AND,
makeTypeTest(make.Ident(currentValue), make.Type(principalType)),

@ -764,26 +764,26 @@ public class JavacParser implements Parser {
*/
public JCPattern parsePattern(int pos, JCModifiers mods, JCExpression parsedType, boolean inInstanceOf) {
JCPattern pattern;
if (token.kind == LPAREN && parsedType == null) {
int startPos = token.pos;
accept(LPAREN);
JCPattern p = parsePattern(token.pos, null, null, false);
accept(RPAREN);
return toP(F.at(startPos).ParenthesizedPattern(p));
pattern = toP(F.at(startPos).ParenthesizedPattern(p));
} else {
JCPattern pattern;
JCExpression e = parsedType == null ? term(EXPR | TYPE | NOLAMBDA) : parsedType;
mods = mods != null ? mods : F.at(token.pos).Modifiers(0);
JCVariableDecl var = toP(F.at(token.pos).VarDef(mods, ident(), e, null));
pattern = toP(F.at(pos).BindingPattern(var));
if (!inInstanceOf && token.kind == AMPAMP) {
checkSourceLevel(Feature.PATTERN_SWITCH);
nextToken();
JCExpression guard = term(EXPR | NOLAMBDA);
pattern = F.at(pos).GuardPattern(pattern, guard);
}
return pattern;
}
if (!inInstanceOf && token.kind == AMPAMP) {
checkSourceLevel(Feature.PATTERN_SWITCH);
nextToken();
JCExpression guard = term(EXPR | NOLAMBDA);
pattern = F.at(pos).GuardPattern(pattern, guard);
}
return pattern;
}
/**
@ -1694,12 +1694,16 @@ public class JavacParser implements Parser {
* method reference or a binary expression. To disambiguate, look for a
* matching '&gt;' and see if the subsequent terminal is either '.' or '::'.
*/
@SuppressWarnings("fallthrough")
ParensResult analyzeParens() {
return analyzeParens(0);
}
@SuppressWarnings("fallthrough")
ParensResult analyzeParens(int startLookahead) {
int depth = 0;
boolean type = false;
ParensResult defaultResult = ParensResult.PARENS;
outer: for (int lookahead = 0; ; lookahead++) {
outer: for (int lookahead = startLookahead; ; lookahead++) {
TokenKind tk = S.token(lookahead).kind;
switch (tk) {
case COMMA:
@ -1725,7 +1729,7 @@ public class JavacParser implements Parser {
}
break;
case LPAREN:
if (lookahead != 0) {
if (lookahead != startLookahead) {
// '(' in a non-starting position -> parens
return ParensResult.PARENS;
} else if (peekToken(lookahead, RPAREN)) {
@ -3065,15 +3069,12 @@ public class JavacParser implements Parser {
} else {
if (token.kind == LPAREN) {
int lookahead = 0;
Token ahead;
while ((ahead = S.token(lookahead)).kind != EOF && ahead.kind != RPAREN && ahead.kind != AMPAMP) {
while (S.token(lookahead + 1).kind == LPAREN) {
lookahead++;
}
Token twoBack;
boolean pattern = S.token(lookahead - 1).kind == IDENTIFIER &&
((twoBack = S.token(lookahead - 2)).kind == IDENTIFIER ||
twoBack.kind == GT || twoBack.kind == GTGT || twoBack.kind == GTGTGT);
boolean pattern = analyzeParens(lookahead) == ParensResult.EXPLICIT_LAMBDA;
if (pattern) {
checkSourceLevel(token.pos, Feature.PATTERN_SWITCH);
return parsePattern(token.pos, null, null, false);
} else {
return term(EXPR | TYPE | NOLAMBDA);

@ -1367,6 +1367,15 @@ public class TreeInfo {
};
}
public static JCBindingPattern primaryPatternTree(JCPattern pat) {
return switch (pat.getTag()) {
case BINDINGPATTERN -> (JCBindingPattern) pat;
case GUARDPATTERN -> primaryPatternTree(((JCGuardPattern) pat).patt);
case PARENTHESIZEDPATTERN -> primaryPatternTree(((JCParenthesizedPattern) pat).pattern);
default -> throw new AssertionError();
};
}
public record PatternPrimaryType(Type type, boolean unconditional) {}
}

@ -33,6 +33,7 @@ import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import jdk.internal.misc.ScopedMemoryAccess;
import jdk.internal.misc.Unsafe;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.vector.VectorSupport;
@ -3562,15 +3563,14 @@ public abstract class ByteVector extends AbstractVector<Byte> {
final
ByteVector fromByteBuffer0Template(ByteBuffer bb, int offset) {
ByteSpecies vsp = vspecies();
return VectorSupport.load(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bufferBase(bb), bufferAddress(bb, offset),
bb, offset, vsp,
(buf, off, s) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
return s.ldOp(wb, off,
(wb_, o, i) -> wb_.get(o + i * 1));
});
return ScopedMemoryAccess.loadFromByteBuffer(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bb, offset, vsp,
(buf, off, s) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
return s.ldOp(wb, off,
(wb_, o, i) -> wb_.get(o + i * 1));
});
}
// Unchecked storing operations in native byte order.
@ -3613,15 +3613,14 @@ public abstract class ByteVector extends AbstractVector<Byte> {
final
void intoByteBuffer0(ByteBuffer bb, int offset) {
ByteSpecies vsp = vspecies();
VectorSupport.store(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bufferBase(bb), bufferAddress(bb, offset),
this, bb, offset,
(buf, off, v) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
v.stOp(wb, off,
(wb_, o, i, e) -> wb_.put(o + i * 1, e));
});
ScopedMemoryAccess.storeIntoByteBuffer(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
this, bb, offset,
(buf, off, v) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
v.stOp(wb, off,
(wb_, o, i, e) -> wb_.put(o + i * 1, e));
});
}
// End of low-level memory operations.

@ -33,6 +33,7 @@ import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import jdk.internal.misc.ScopedMemoryAccess;
import jdk.internal.misc.Unsafe;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.vector.VectorSupport;
@ -3173,15 +3174,14 @@ public abstract class DoubleVector extends AbstractVector<Double> {
final
DoubleVector fromByteBuffer0Template(ByteBuffer bb, int offset) {
DoubleSpecies vsp = vspecies();
return VectorSupport.load(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bufferBase(bb), bufferAddress(bb, offset),
bb, offset, vsp,
(buf, off, s) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
return s.ldOp(wb, off,
(wb_, o, i) -> wb_.getDouble(o + i * 8));
});
return ScopedMemoryAccess.loadFromByteBuffer(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bb, offset, vsp,
(buf, off, s) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
return s.ldOp(wb, off,
(wb_, o, i) -> wb_.getDouble(o + i * 8));
});
}
// Unchecked storing operations in native byte order.
@ -3224,15 +3224,14 @@ public abstract class DoubleVector extends AbstractVector<Double> {
final
void intoByteBuffer0(ByteBuffer bb, int offset) {
DoubleSpecies vsp = vspecies();
VectorSupport.store(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bufferBase(bb), bufferAddress(bb, offset),
this, bb, offset,
(buf, off, v) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
v.stOp(wb, off,
(wb_, o, i, e) -> wb_.putDouble(o + i * 8, e));
});
ScopedMemoryAccess.storeIntoByteBuffer(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
this, bb, offset,
(buf, off, v) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
v.stOp(wb, off,
(wb_, o, i, e) -> wb_.putDouble(o + i * 8, e));
});
}
// End of low-level memory operations.

@ -33,6 +33,7 @@ import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import jdk.internal.misc.ScopedMemoryAccess;
import jdk.internal.misc.Unsafe;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.vector.VectorSupport;
@ -3160,15 +3161,14 @@ public abstract class FloatVector extends AbstractVector<Float> {
final
FloatVector fromByteBuffer0Template(ByteBuffer bb, int offset) {
FloatSpecies vsp = vspecies();
return VectorSupport.load(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bufferBase(bb), bufferAddress(bb, offset),
bb, offset, vsp,
(buf, off, s) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
return s.ldOp(wb, off,
(wb_, o, i) -> wb_.getFloat(o + i * 4));
});
return ScopedMemoryAccess.loadFromByteBuffer(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bb, offset, vsp,
(buf, off, s) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
return s.ldOp(wb, off,
(wb_, o, i) -> wb_.getFloat(o + i * 4));
});
}
// Unchecked storing operations in native byte order.
@ -3211,15 +3211,14 @@ public abstract class FloatVector extends AbstractVector<Float> {
final
void intoByteBuffer0(ByteBuffer bb, int offset) {
FloatSpecies vsp = vspecies();
VectorSupport.store(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bufferBase(bb), bufferAddress(bb, offset),
this, bb, offset,
(buf, off, v) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
v.stOp(wb, off,
(wb_, o, i, e) -> wb_.putFloat(o + i * 4, e));
});
ScopedMemoryAccess.storeIntoByteBuffer(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
this, bb, offset,
(buf, off, v) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
v.stOp(wb, off,
(wb_, o, i, e) -> wb_.putFloat(o + i * 4, e));
});
}
// End of low-level memory operations.

@ -33,6 +33,7 @@ import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import jdk.internal.misc.ScopedMemoryAccess;
import jdk.internal.misc.Unsafe;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.vector.VectorSupport;
@ -3269,15 +3270,14 @@ public abstract class IntVector extends AbstractVector<Integer> {
final
IntVector fromByteBuffer0Template(ByteBuffer bb, int offset) {
IntSpecies vsp = vspecies();
return VectorSupport.load(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bufferBase(bb), bufferAddress(bb, offset),
bb, offset, vsp,
(buf, off, s) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
return s.ldOp(wb, off,
(wb_, o, i) -> wb_.getInt(o + i * 4));
});
return ScopedMemoryAccess.loadFromByteBuffer(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bb, offset, vsp,
(buf, off, s) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
return s.ldOp(wb, off,
(wb_, o, i) -> wb_.getInt(o + i * 4));
});
}
// Unchecked storing operations in native byte order.
@ -3320,15 +3320,14 @@ public abstract class IntVector extends AbstractVector<Integer> {
final
void intoByteBuffer0(ByteBuffer bb, int offset) {
IntSpecies vsp = vspecies();
VectorSupport.store(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bufferBase(bb), bufferAddress(bb, offset),
this, bb, offset,
(buf, off, v) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
v.stOp(wb, off,
(wb_, o, i, e) -> wb_.putInt(o + i * 4, e));
});
ScopedMemoryAccess.storeIntoByteBuffer(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
this, bb, offset,
(buf, off, v) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
v.stOp(wb, off,
(wb_, o, i, e) -> wb_.putInt(o + i * 4, e));
});
}
// End of low-level memory operations.

@ -33,6 +33,7 @@ import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import jdk.internal.misc.ScopedMemoryAccess;
import jdk.internal.misc.Unsafe;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.vector.VectorSupport;
@ -3172,15 +3173,14 @@ public abstract class LongVector extends AbstractVector<Long> {
final
LongVector fromByteBuffer0Template(ByteBuffer bb, int offset) {
LongSpecies vsp = vspecies();
return VectorSupport.load(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bufferBase(bb), bufferAddress(bb, offset),
bb, offset, vsp,
(buf, off, s) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
return s.ldOp(wb, off,
(wb_, o, i) -> wb_.getLong(o + i * 8));
});
return ScopedMemoryAccess.loadFromByteBuffer(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bb, offset, vsp,
(buf, off, s) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
return s.ldOp(wb, off,
(wb_, o, i) -> wb_.getLong(o + i * 8));
});
}
// Unchecked storing operations in native byte order.
@ -3223,15 +3223,14 @@ public abstract class LongVector extends AbstractVector<Long> {
final
void intoByteBuffer0(ByteBuffer bb, int offset) {
LongSpecies vsp = vspecies();
VectorSupport.store(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bufferBase(bb), bufferAddress(bb, offset),
this, bb, offset,
(buf, off, v) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
v.stOp(wb, off,
(wb_, o, i, e) -> wb_.putLong(o + i * 8, e));
});
ScopedMemoryAccess.storeIntoByteBuffer(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
this, bb, offset,
(buf, off, v) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
v.stOp(wb, off,
(wb_, o, i, e) -> wb_.putLong(o + i * 8, e));
});
}
// End of low-level memory operations.

@ -33,6 +33,7 @@ import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import jdk.internal.misc.ScopedMemoryAccess;
import jdk.internal.misc.Unsafe;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.vector.VectorSupport;
@ -3549,15 +3550,14 @@ public abstract class ShortVector extends AbstractVector<Short> {
final
ShortVector fromByteBuffer0Template(ByteBuffer bb, int offset) {
ShortSpecies vsp = vspecies();
return VectorSupport.load(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bufferBase(bb), bufferAddress(bb, offset),
bb, offset, vsp,
(buf, off, s) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
return s.ldOp(wb, off,
(wb_, o, i) -> wb_.getShort(o + i * 2));
});
return ScopedMemoryAccess.loadFromByteBuffer(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bb, offset, vsp,
(buf, off, s) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
return s.ldOp(wb, off,
(wb_, o, i) -> wb_.getShort(o + i * 2));
});
}
// Unchecked storing operations in native byte order.
@ -3600,15 +3600,14 @@ public abstract class ShortVector extends AbstractVector<Short> {
final
void intoByteBuffer0(ByteBuffer bb, int offset) {
ShortSpecies vsp = vspecies();
VectorSupport.store(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bufferBase(bb), bufferAddress(bb, offset),
this, bb, offset,
(buf, off, v) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
v.stOp(wb, off,
(wb_, o, i, e) -> wb_.putShort(o + i * 2, e));
});
ScopedMemoryAccess.storeIntoByteBuffer(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
this, bb, offset,
(buf, off, v) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
v.stOp(wb, off,
(wb_, o, i, e) -> wb_.putShort(o + i * 2, e));
});
}
// End of low-level memory operations.

@ -24,33 +24,11 @@
*/
package jdk.incubator.vector;
import jdk.internal.misc.Unsafe;
import jdk.internal.vm.annotation.ForceInline;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.Objects;
/*non-public*/ class VectorIntrinsics {
static final Unsafe U = Unsafe.getUnsafe();
static final long BUFFER_ADDRESS
= U.objectFieldOffset(Buffer.class, "address");
// Buffer.limit
static final long BUFFER_LIMIT
= U.objectFieldOffset(Buffer.class, "limit");
// ByteBuffer.hb
static final long BYTE_BUFFER_HB
= U.objectFieldOffset(ByteBuffer.class, "hb");
// ByteBuffer.isReadOnly
static final long BYTE_BUFFER_IS_READ_ONLY
= U.objectFieldOffset(ByteBuffer.class, "isReadOnly");
/* ============================================================================ */
static final int VECTOR_ACCESS_OOB_CHECK = Integer.getInteger("jdk.incubator.vector.VECTOR_ACCESS_OOB_CHECK", 2);
@ForceInline
@ -133,18 +111,4 @@ import java.util.Objects;
return Math.floorMod(index, Math.abs(size));
}
}
/* ============================================================================ */
/*package-private*/
@ForceInline
static Object bufferBase(ByteBuffer bb) {
return U.getReference(bb, BYTE_BUFFER_HB);
}
/*package-private*/
@ForceInline
static long bufferAddress(ByteBuffer bb, long offset) {
return U.getLong(bb, BUFFER_ADDRESS) + offset;
}
}

@ -33,6 +33,7 @@ import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import jdk.internal.misc.ScopedMemoryAccess;
import jdk.internal.misc.Unsafe;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.vector.VectorSupport;
@ -4517,15 +4518,14 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
final
$abstractvectortype$ fromByteBuffer0Template(ByteBuffer bb, int offset) {
$Type$Species vsp = vspecies();
return VectorSupport.load(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bufferBase(bb), bufferAddress(bb, offset),
bb, offset, vsp,
(buf, off, s) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
return s.ldOp(wb, off,
(wb_, o, i) -> wb_.get{#if[byte]?(:$Type$(}o + i * $sizeInBytes$));
});
return ScopedMemoryAccess.loadFromByteBuffer(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bb, offset, vsp,
(buf, off, s) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
return s.ldOp(wb, off,
(wb_, o, i) -> wb_.get{#if[byte]?(:$Type$(}o + i * $sizeInBytes$));
});
}
// Unchecked storing operations in native byte order.
@ -4568,15 +4568,14 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
final
void intoByteBuffer0(ByteBuffer bb, int offset) {
$Type$Species vsp = vspecies();
VectorSupport.store(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
bufferBase(bb), bufferAddress(bb, offset),
this, bb, offset,
(buf, off, v) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
v.stOp(wb, off,
(wb_, o, i, e) -> wb_.put{#if[byte]?(:$Type$(}o + i * $sizeInBytes$, e));
});
ScopedMemoryAccess.storeIntoByteBuffer(
vsp.vectorType(), vsp.elementType(), vsp.laneCount(),
this, bb, offset,
(buf, off, v) -> {
ByteBuffer wb = wrapper(buf, NATIVE_ENDIAN);
v.stOp(wb, off,
(wb_, o, i, e) -> wb_.put{#if[byte]?(:$Type$(}o + i * $sizeInBytes$, e));
});
}
// End of low-level memory operations.

@ -94,6 +94,12 @@ public interface Reporter {
* The positions are all 0-based character offsets from the beginning of content of the file.
* The positions should satisfy the relation {@code start <= pos <= end}.
*
* @implSpec
* This implementation always throws {@code UnsupportedOperationException}.
* The implementation provided by the {@code javadoc} tool to
* {@link Doclet#init(Locale, Reporter) initialize} a doclet
* overrides this implementation.
*
* @param kind the kind of diagnostic
* @param file the file
* @param start the beginning of the enclosing range
@ -103,7 +109,9 @@ public interface Reporter {
*
* @since 17
*/
void print(Diagnostic.Kind kind, FileObject file, int start, int pos, int end, String message);
default void print(Diagnostic.Kind kind, FileObject file, int start, int pos, int end, String message) {
throw new UnsupportedOperationException();
}
/**
* Returns a writer that can be used to write non-diagnostic output,

@ -346,7 +346,11 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
"-volname", APP_NAME.fetchFrom(params),
"-ov", protoDMG.toAbsolutePath().toString(),
"-fs", "HFS+");
IOUtils.exec(pb, false, null, true, Executor.INFINITE_TIMEOUT);
new RetryExecutor()
.setMaxAttemptsCount(10)
.setAttemptTimeoutMillis(3000)
.setWriteOutputToFile(true)
.execute(pb);
}
// mount temp image

@ -32,6 +32,7 @@ public final class RetryExecutor {
public RetryExecutor() {
setMaxAttemptsCount(5);
setAttemptTimeoutMillis(2 * 1000);
setWriteOutputToFile(false);
}
public RetryExecutor setMaxAttemptsCount(int v) {
@ -44,6 +45,11 @@ public final class RetryExecutor {
return this;
}
RetryExecutor setWriteOutputToFile(boolean v) {
writeOutputToFile = v;
return this;
}
public RetryExecutor setExecutorInitializer(Consumer<Executor> v) {
executorInitializer = v;
return this;
@ -69,11 +75,13 @@ public final class RetryExecutor {
}
public void execute(String cmdline[]) throws IOException {
executeLoop(() -> Executor.of(cmdline));
executeLoop(() ->
Executor.of(cmdline).setWriteOutputToFile(writeOutputToFile));
}
public void execute(ProcessBuilder pb) throws IOException {
executeLoop(() -> Executor.of(pb));
executeLoop(() ->
Executor.of(pb).setWriteOutputToFile(writeOutputToFile));
}
private void executeLoop(Supplier<Executor> execSupplier) throws IOException {
@ -109,4 +117,5 @@ public final class RetryExecutor {
private boolean aborted;
private int attempts;
private int timeoutMillis;
private boolean writeOutputToFile;
}

@ -31,4 +31,4 @@ compiler/intrinsics/bmi/verifycode/BzhiTestI2L.java 8268033 generic-x64
vmTestbase/nsk/jvmti/SetFieldAccessWatch/setfldw001/TestDescription.java 8205957 generic-all
vmTestbase/vm/mlvm/mixed/stress/regression/b6969574/INDIFY_Test.java 8265295 windows-x64
vmTestbase/vm/mlvm/mixed/stress/regression/b6969574/INDIFY_Test.java 8265295 linux-x64,windows-x64

@ -39,4 +39,4 @@ serviceability/sa/ClhsdbFindPC.java#id3 8268722 macosx-x
serviceability/sa/ClhsdbPmap.java#id1 8268722 macosx-x64
serviceability/sa/ClhsdbPstack.java#id1 8268722 macosx-x64
serviceability/sa/TestJmapCore.java 8268722,8268283 macosx-x64,linux-aarch64
serviceability/sa/TestJmapCoreMetaspace.java 8268722,8268636 macosx-x64,linux-x64
serviceability/sa/TestJmapCoreMetaspace.java 8268722,8268636 generic-all

@ -70,7 +70,6 @@ compiler/whitebox/MakeMethodNotCompilableTest.java 8265360 macosx-aarch64
compiler/codecache/jmx/PoolsIndependenceTest.java 8264632 macosx-x64
compiler/intrinsics/VectorizedMismatchTest.java 8268482 windows-x64
#############################################################################
@ -111,7 +110,7 @@ resourcehogs/serviceability/sa/TestHeapDumpForLargeArray.java 8262386 generic-al
serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatIntervalTest.java 8214032 generic-all
serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatArrayCorrectnessTest.java 8224150 generic-all
serviceability/jvmti/ModuleAwareAgents/ThreadStart/MAAThreadStart.java 8225354 windows-all
serviceability/dcmd/gc/RunFinalizationTest.java 8227120 linux-x64
serviceability/dcmd/gc/RunFinalizationTest.java 8227120 linux-all,windows-x64
serviceability/jvmti/CompiledMethodLoad/Zombie.java 8245877 linux-aarch64
#############################################################################

@ -71,6 +71,29 @@ hotspot_native_sanity = \
hotspot_containers = \
containers
hotspot_vector_1 = \
compiler/c2/cr6340864 \
compiler/codegen \
compiler/loopopts/superword \
compiler/vectorapi \
compiler/vectorization \
-compiler/codegen/aes \
-compiler/codegen/Test6875866.java \
-compiler/codegen/Test6935535.java \
-compiler/codegen/TestGCMStorePlacement.java \
-compiler/codegen/TestTrichotomyExpressions.java \
-compiler/loopopts/superword/Vec_MulAddS2I.java \
-compiler/vectorapi/VectorRebracket128Test.java
hotspot_vector_2 = \
compiler/intrinsics \
compiler/codegen/aes \
compiler/codegen/Test6875866.java \
compiler/codegen/Test6935535.java \
compiler/loopopts/superword/Vec_MulAddS2I.java \
compiler/vectorapi/VectorRebracket128Test.java \
-compiler/intrinsics/string/TestStringLatin1IndexOfChar.java
tier1_common = \
sanity/BasicVMTest.java \
gtest/GTestWrapper.java \

@ -263,8 +263,8 @@ public class AArch64TestAssembler extends TestAssembler {
@Override
public void emitEpilogue() {
recordMark(config.MARKID_DEOPT_HANDLER_ENTRY);
recordCall(new HotSpotForeignCallTarget(config.handleDeoptStub), 5, true, null);
code.emitInt(0x94000000); // bl <imm26>
recordCall(new HotSpotForeignCallTarget(config.handleDeoptStub), 4*4, true, null);
emitCall(0xdeaddeaddeadL);
}
@Override
@ -285,7 +285,7 @@ public class AArch64TestAssembler extends TestAssembler {
@Override
public void emitCall(long addr) {
emitLoadLong(scratchRegister, addr);
emitLoadPointer48(scratchRegister, addr);
emitBlr(scratchRegister);
}
@ -320,20 +320,39 @@ public class AArch64TestAssembler extends TestAssembler {
}
}
private void emitLoadPointer32(Register ret, long addr) {
long a = addr;
long al = a;
a >>= 16;
long ah = a;
a >>= 16;
assert a == 0 : "invalid pointer" + Long.toHexString(addr);
// Set upper 16 bits first. See MacroAssembler::patch_oop().
emitMovz(ret, ((int)ah & 0xffff), 16);
emitMovk(ret, ((int)al & 0xffff), 0);
}
private void emitLoadPointer48(Register ret, long addr) {
// 48-bit VA
long a = addr;
emitMovz(ret, ((int)a & 0xffff), 0);
a >>= 16;
emitMovk(ret, ((int)a & 0xffff), 16);
a >>= 16;
emitMovk(ret, ((int)a & 0xffff), 32);
a >>= 16;
assert a == 0 : "invalid pointer" + Long.toHexString(addr);
}
@Override
public Register emitLoadPointer(HotSpotConstant c) {
recordDataPatchInCode(new ConstantReference((VMConstant) c));
Register ret = newRegister();
if (c.isCompressed()) {
// Set upper 16 bits first. See MacroAssembler::patch_oop().
emitMovz(ret, 0xdead, 16);
emitMovk(ret, 0xdead, 0);
emitLoadPointer32(ret, 0xdeaddeadL);
} else {
// 48-bit VA
emitMovz(ret, 0xdead, 0);
emitMovk(ret, 0xdead, 16);
emitMovk(ret, 0xdead, 32);
emitLoadPointer48(ret, 0xdeaddeaddeadL);
}
return ret;
}

@ -234,7 +234,7 @@ public class SocketIOPipe extends Log.Logger implements Finalizable {
public SocketConnection getConnection() {
synchronized (this) {
while (!connection.isConnected() && error != null) {
while (!connection.isConnected() && error == null) {
try {
wait();
} catch (InterruptedException e) {

@ -0,0 +1,71 @@
/*
* Copyright (c) 2021, 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 bcel;
import com.sun.org.apache.bcel.internal.classfile.Utility;
import java.util.Base64;
import org.testng.annotations.Test;
/*
* @test
* @bug 8256919
* @modules java.xml/com.sun.org.apache.bcel.internal.classfile
* @run testng bcel.UtilityTest
* @summary Tests the Utility.
*/
public class UtilityTest {
/*
* @bug 8256919
* Verifies the encode method.
*/
@Test
public void test() throws Exception {
/**
* public class Hello {
* public void hello(){
* System.out.println("Hello,world");
* }
* public static void main(String[] args) {
* Hello hello = new Hello();
* hello.hello();
* }
* }
* javac Hello.java
* cat Hello.class |base64
*/
String bytecodeBase64 = "cHVibGljIGNsYXNzIEhlbGxvIHsKICAgIHB1YmxpYyB2b2lkIGhlbGxvKCl7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJIZWxsbyx3b3JsZCIpOwogICAgfQogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIEhlbGxvIGhlbGxvID0gbmV3IEhlbGxvKCk7CiAgICAgICAgaGVsbG8uaGVsbG8oKTsKICAgIH0KfQo=";
byte[] bytecode = Base64.getDecoder().decode(bytecodeBase64);
// encode regression:
//(jdk1.8.0_171)$l$8b$I$A$A$A$A$A$A$AM$8e$c1$O$c2$m$QD$ef$7c$c5$a6$tH$M$3f$60$bc$7b$ef$d1x$c0$96$b4$q$5b$m$ec$d6$c6$Y$fe$dd$C$g$3b$c7$99$9d$b7$T$d7$H$ba$B$G4Dp$b5$88$B$de$Cv$c5$W$3c$83$ha$$$beT$z$u$ea_$c4v$d1ae$j$93$f3$8c$5ev$b5$7c$daB$c2$b1S$e7z$9a$8f$qb$c3$3f$e0b$9c$97$3d$ef$d5$e9v$H$93$sR$f0$a7$b7$Z$f5$v$5c$c0$db$ad9$f2K$z$aa$a1$9e$8fv$WY$7c$A$93C$7bZ$ce$A$A$A
//(jdk1.8.0_251)$l$8b$I$A$A$A$A$A$A$A
String classname = Utility.encode(bytecode,true);
/* attempting to decode would result in an exception:
* java.io.EOFException: Unexpected end of ZLIB input stream
*if encode is not done properly
*/
Utility.decode(classname, true);
}
}

@ -526,6 +526,7 @@ java/awt/Robot/Delay/InterruptOfDelay.java 8265986 macosx-all
java/awt/MenuBar/TestNoScreenMenuBar.java 8265987 macosx-all
java/awt/Graphics2D/DrawString/DrawRotatedStringUsingRotatedFont.java 8266283 generic-all
java/awt/KeyboardFocusmanager/TypeAhead/ButtonActionKeyTest/ButtonActionKeyTest.java 8257529 windows-x64
############################################################################
@ -741,6 +742,7 @@ javax/swing/Popup/TaskbarPositionTest.java 8065097 macosx-all,linux-all
javax/swing/JEditorPane/6917744/bug6917744.java 8213124 macosx-all
javax/swing/JRootPane/4670486/bug4670486.java 8042381 macosx-all
javax/swing/JPopupMenu/4634626/bug4634626.java 8017175 macosx-all
javax/swing/JFileChooser/FileSystemView/SystemIconTest.java 8268280 windows-x64
sanity/client/SwingSet/src/ToolTipDemoTest.java 8225012 windows-all,macosx-all
sanity/client/SwingSet/src/ScrollPaneDemoTest.java 8225013 linux-all

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, 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
@ -22,7 +22,7 @@
*/
/* @test
* @bug 8206955
* @bug 8206955 8269351
* @run testng/othervm -ea -esa test.java.lang.invoke.MethodHandlesProxiesTest
*/
@ -99,4 +99,24 @@ public class MethodHandlesProxiesTest {
assertEquals(proxy.b(), "OB");
assertEquals(proxy.c(), "OC");
}
public sealed interface Intf permits NonSealedInterface {
String m();
}
public non-sealed interface NonSealedInterface extends Intf {
}
@Test(expectedExceptions = { IllegalArgumentException.class })
public void testSealedInterface() {
MethodHandle target = MethodHandles.constant(String.class, "Sealed");
MethodHandleProxies.asInterfaceInstance(Intf.class, target);
}
@Test
public void testNonSealedInterface() {
MethodHandle target = MethodHandles.constant(String.class, "Non-Sealed");
NonSealedInterface proxy = MethodHandleProxies.asInterfaceInstance(NonSealedInterface.class, target);
assertEquals(proxy.m(), "Non-Sealed");
}
}

@ -24,13 +24,17 @@
*/
/* @test
* @bug 8150782 8207027
* @compile TestAccessClass.java TestCls.java
* @bug 8150782 8207027 8266269
* @compile TestAccessClass.java TestCls.java p/Foo.java q/Bar.java
* @run testng/othervm -ea -esa test.java.lang.invoke.t8150782.TestAccessClass
*/
package test.java.lang.invoke.t8150782;
import java.lang.invoke.*;
import java.lang.reflect.Modifier;
import p.Foo;
import q.Bar;
import static java.lang.invoke.MethodHandles.*;
@ -55,13 +59,13 @@ public class TestAccessClass {
}
@Test
public void returnsSameClassInSamePackage() throws IllegalAccessException, ClassNotFoundException {
public void returnsSameClassInSamePackage() throws IllegalAccessException {
Class<?> aClass = lookup().accessClass(Class1.class);
assertEquals(Class1.class, aClass);
}
@Test
public void returnsSameArrayClassInSamePackage() throws IllegalAccessException, ClassNotFoundException {
public void returnsSameArrayClassInSamePackage() throws IllegalAccessException {
Class<?> aClass = lookup().accessClass(Class1[].class);
assertEquals(Class1[].class, aClass);
}
@ -75,7 +79,7 @@ public class TestAccessClass {
}
@Test(dataProvider = "illegalAccessAccess", expectedExceptions = {IllegalAccessException.class})
public void illegalAccessExceptionTest(Lookup lookup, Class<?> klass) throws IllegalAccessException, ClassNotFoundException {
public void illegalAccessExceptionTest(Lookup lookup, Class<?> klass) throws IllegalAccessException {
lookup.accessClass(klass);
}
@ -84,4 +88,20 @@ public class TestAccessClass {
lookup().accessClass(TestCls.getPrivateSIC());
}
/**
* Verify that a protected Q is as accessible as a public Q during linkage
* (see JLS 15.12.4.3).
*/
@Test
public void protectedInnerClass() throws Throwable {
lookup().accessClass(Bar.T_CLS);
lookup().accessClass(Bar.T_ARRAY_CLS);
MethodHandle mh = lookup().findStatic(Bar.class, "meth", MethodType.methodType(void.class, Bar.T_ARRAY_CLS));
mh.invoke(null);
}
@Test(expectedExceptions = {NullPointerException.class})
public void illegalArgument() throws IllegalAccessException {
lookup().accessClass(null);
}
}

@ -24,13 +24,15 @@
*/
/* @test
* @bug 8150782 8207027
* @compile TestFindClass.java TestCls.java
* @bug 8150782 8207027 8266269
* @compile TestFindClass.java TestCls.java p/Foo.java q/Bar.java
* @run testng/othervm -ea -esa test.java.lang.invoke.t8150782.TestFindClass
*/
package test.java.lang.invoke.t8150782;
import java.lang.invoke.*;
import p.Foo;
import q.Bar;
import static java.lang.invoke.MethodHandles.*;
@ -94,4 +96,18 @@ public class TestFindClass {
lookup().findClass(PACKAGE_PREFIX + "TestCls$PrivateSIC");
}
/**
* Verify that a protected Q is as accessible as a public Q during linkage
* (see JLS 15.12.4.3).
*/
@Test
public void protectedInnerClass() throws IllegalAccessException, ClassNotFoundException {
lookup().findClass("p.Foo$T");
lookup().findClass("[Lp.Foo$T;");
}
@Test(expectedExceptions = {NullPointerException.class})
public void illegalArgument() throws IllegalAccessException, ClassNotFoundException {
lookup().findClass(null);
}
}

@ -0,0 +1,30 @@
/*
* Copyright (c) 2021, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 p;
public class Foo {
protected enum T { ONE }
}

@ -0,0 +1,37 @@
/*
* Copyright (c) 2021, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 q;
import p.Foo;
// access protected inner class Foo.T
public class Bar extends Foo {
public static final Class<?> T_CLS = T.class;
public static final Class<?> T_ARRAY_CLS = T[].class;
public static void meth(T[] arr) {
System.out.println("called method");
}
}

@ -0,0 +1,69 @@
/*
* Copyright (c) 2021, 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 8269351
* @run testng SealedInterfaceTest
*/
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
public class SealedInterfaceTest {
sealed interface Intf permits NonSealedInterface {
void m1();
}
non-sealed interface NonSealedInterface extends Intf {
void m2();
}
@Test(expectedExceptions = { IllegalArgumentException.class })
public void testSealedInterface() {
Proxy.newProxyInstance(SealedInterfaceTest.class.getClassLoader(),
new Class<?>[]{ Intf.class },
new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return null;
}
});
}
@Test
public void testNonSealedInterface() {
Proxy.newProxyInstance(SealedInterfaceTest.class.getClassLoader(),
new Class<?>[]{ NonSealedInterface.class },
new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return null;
}
});
}
}

@ -0,0 +1,54 @@
/*
* Copyright (c) 2021, 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 jdk.incubator.foreign.MemorySegment;
import jdk.incubator.foreign.ResourceScope;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.function.IntFunction;
public class AbstractVectorLoadStoreTest extends AbstractVectorTest {
static final Collection<ByteOrder> BYTE_ORDER_VALUES = Set.of(
ByteOrder.BIG_ENDIAN, ByteOrder.LITTLE_ENDIAN);
static final List<IntFunction<ByteBuffer>> BYTE_BUFFER_GENERATORS = List.of(
withToString("HB:RW:NE", (int s) -> {
return ByteBuffer.allocate(s)
.order(ByteOrder.nativeOrder());
}),
withToString("DB:RW:NE", (int s) -> {
return ByteBuffer.allocateDirect(s)
.order(ByteOrder.nativeOrder());
}),
withToString("MS:RW:NE", (int s) -> {
return MemorySegment.allocateNative(s, ResourceScope.newImplicitScope())
.asByteBuffer()
.order(ByteOrder.nativeOrder());
})
);
}

@ -84,20 +84,6 @@ public class AbstractVectorTest {
};
}
static final Collection<ByteOrder> BYTE_ORDER_VALUES = Set.of(
ByteOrder.BIG_ENDIAN, ByteOrder.LITTLE_ENDIAN);
static final List<IntFunction<ByteBuffer>> BYTE_BUFFER_GENERATORS = List.of(
withToString("HB:RW:NE", (int s) -> {
return ByteBuffer.allocate(s)
.order(ByteOrder.nativeOrder());
}),
withToString("DB:RW:NE", (int s) -> {
return ByteBuffer.allocateDirect(s)
.order(ByteOrder.nativeOrder());
})
);
static final List<IntFunction<boolean[]>> BOOL_ARRAY_GENERATORS = List.of(
withToString("boolean[i % 2]", (int s) -> {
return fill_boolean(s,

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Byte128VectorLoadStoreTests
*
*/
@ -42,12 +42,11 @@ import org.testng.annotations.Test;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Byte128VectorLoadStoreTests extends AbstractVectorTest {
public class Byte128VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Byte> SPECIES =
ByteVector.SPECIES_128;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Byte256VectorLoadStoreTests
*
*/
@ -42,12 +42,11 @@ import org.testng.annotations.Test;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Byte256VectorLoadStoreTests extends AbstractVectorTest {
public class Byte256VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Byte> SPECIES =
ByteVector.SPECIES_256;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Byte512VectorLoadStoreTests
*
*/
@ -42,12 +42,11 @@ import org.testng.annotations.Test;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Byte512VectorLoadStoreTests extends AbstractVectorTest {
public class Byte512VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Byte> SPECIES =
ByteVector.SPECIES_512;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Byte64VectorLoadStoreTests
*
*/
@ -42,12 +42,11 @@ import org.testng.annotations.Test;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Byte64VectorLoadStoreTests extends AbstractVectorTest {
public class Byte64VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Byte> SPECIES =
ByteVector.SPECIES_64;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm --add-opens jdk.incubator.vector/jdk.incubator.vector=ALL-UNNAMED
* -XX:-TieredCompilation ByteMaxVectorLoadStoreTests
*
@ -46,12 +46,11 @@ import java.lang.invoke.VarHandle;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class ByteMaxVectorLoadStoreTests extends AbstractVectorTest {
public class ByteMaxVectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Byte> SPECIES =
ByteVector.SPECIES_MAX;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Double128VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Double128VectorLoadStoreTests extends AbstractVectorTest {
public class Double128VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Double> SPECIES =
DoubleVector.SPECIES_128;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Double256VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Double256VectorLoadStoreTests extends AbstractVectorTest {
public class Double256VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Double> SPECIES =
DoubleVector.SPECIES_256;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Double512VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Double512VectorLoadStoreTests extends AbstractVectorTest {
public class Double512VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Double> SPECIES =
DoubleVector.SPECIES_512;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Double64VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Double64VectorLoadStoreTests extends AbstractVectorTest {
public class Double64VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Double> SPECIES =
DoubleVector.SPECIES_64;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm --add-opens jdk.incubator.vector/jdk.incubator.vector=ALL-UNNAMED
* -XX:-TieredCompilation DoubleMaxVectorLoadStoreTests
*
@ -47,12 +47,11 @@ import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class DoubleMaxVectorLoadStoreTests extends AbstractVectorTest {
public class DoubleMaxVectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Double> SPECIES =
DoubleVector.SPECIES_MAX;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Float128VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Float128VectorLoadStoreTests extends AbstractVectorTest {
public class Float128VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Float> SPECIES =
FloatVector.SPECIES_128;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Float256VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Float256VectorLoadStoreTests extends AbstractVectorTest {
public class Float256VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Float> SPECIES =
FloatVector.SPECIES_256;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Float512VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Float512VectorLoadStoreTests extends AbstractVectorTest {
public class Float512VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Float> SPECIES =
FloatVector.SPECIES_512;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Float64VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Float64VectorLoadStoreTests extends AbstractVectorTest {
public class Float64VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Float> SPECIES =
FloatVector.SPECIES_64;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm --add-opens jdk.incubator.vector/jdk.incubator.vector=ALL-UNNAMED
* -XX:-TieredCompilation FloatMaxVectorLoadStoreTests
*
@ -47,12 +47,11 @@ import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class FloatMaxVectorLoadStoreTests extends AbstractVectorTest {
public class FloatMaxVectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Float> SPECIES =
FloatVector.SPECIES_MAX;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Int128VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Int128VectorLoadStoreTests extends AbstractVectorTest {
public class Int128VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Integer> SPECIES =
IntVector.SPECIES_128;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Int256VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Int256VectorLoadStoreTests extends AbstractVectorTest {
public class Int256VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Integer> SPECIES =
IntVector.SPECIES_256;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Int512VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Int512VectorLoadStoreTests extends AbstractVectorTest {
public class Int512VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Integer> SPECIES =
IntVector.SPECIES_512;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Int64VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Int64VectorLoadStoreTests extends AbstractVectorTest {
public class Int64VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Integer> SPECIES =
IntVector.SPECIES_64;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm --add-opens jdk.incubator.vector/jdk.incubator.vector=ALL-UNNAMED
* -XX:-TieredCompilation IntMaxVectorLoadStoreTests
*
@ -47,12 +47,11 @@ import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class IntMaxVectorLoadStoreTests extends AbstractVectorTest {
public class IntMaxVectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Integer> SPECIES =
IntVector.SPECIES_MAX;

@ -0,0 +1,72 @@
/*
* Copyright (c) 2021, 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 8269335
* @summary Tests SVML shared library is loaded successfully.
* @modules jdk.incubator.vector
* @requires vm.compiler2.enabled
* @requires os.arch == "x86_64" | os.arch == "amd64"
* @requires os.family == "linux" | os.family == "windows"
* @library /test/lib
* @run main LoadSvmlTest
*/
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.incubator.vector.FloatVector;
import jdk.incubator.vector.VectorOperators;
import jdk.incubator.vector.Vector;
import jdk.incubator.vector.VectorSpecies;
public class LoadSvmlTest {
private static class VectorTest {
static final VectorSpecies<Float> SPECIES = FloatVector.SPECIES_PREFERRED;
public static void main(String[] args) throws Exception {
float a[] = new float [1024];
float r[] = new float [1024];
for (int i = 0; i < a.length; i += SPECIES.length()) {
FloatVector av = FloatVector.fromArray(SPECIES, a, i);
av.lanewise(VectorOperators.SINH).intoArray(r, i);
}
}
}
public static void main(String... args) throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-Xmn8m", "-Xlog:library=info",
"--add-modules=jdk.incubator.vector",
VectorTest.class.getName());
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldHaveExitValue(0);
output.shouldMatch("Loaded library .*svml");
}
}

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Long128VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.LongBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Long128VectorLoadStoreTests extends AbstractVectorTest {
public class Long128VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Long> SPECIES =
LongVector.SPECIES_128;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Long256VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.LongBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Long256VectorLoadStoreTests extends AbstractVectorTest {
public class Long256VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Long> SPECIES =
LongVector.SPECIES_256;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Long512VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.LongBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Long512VectorLoadStoreTests extends AbstractVectorTest {
public class Long512VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Long> SPECIES =
LongVector.SPECIES_512;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Long64VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.LongBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Long64VectorLoadStoreTests extends AbstractVectorTest {
public class Long64VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Long> SPECIES =
LongVector.SPECIES_64;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm --add-opens jdk.incubator.vector/jdk.incubator.vector=ALL-UNNAMED
* -XX:-TieredCompilation LongMaxVectorLoadStoreTests
*
@ -47,12 +47,11 @@ import java.nio.ByteBuffer;
import java.nio.LongBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class LongMaxVectorLoadStoreTests extends AbstractVectorTest {
public class LongMaxVectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Long> SPECIES =
LongVector.SPECIES_MAX;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Short128VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.ShortBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Short128VectorLoadStoreTests extends AbstractVectorTest {
public class Short128VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Short> SPECIES =
ShortVector.SPECIES_128;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Short256VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.ShortBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Short256VectorLoadStoreTests extends AbstractVectorTest {
public class Short256VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Short> SPECIES =
ShortVector.SPECIES_256;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Short512VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.ShortBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Short512VectorLoadStoreTests extends AbstractVectorTest {
public class Short512VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Short> SPECIES =
ShortVector.SPECIES_512;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm -XX:-TieredCompilation Short64VectorLoadStoreTests
*
*/
@ -43,12 +43,11 @@ import java.nio.ByteBuffer;
import java.nio.ShortBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class Short64VectorLoadStoreTests extends AbstractVectorTest {
public class Short64VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Short> SPECIES =
ShortVector.SPECIES_64;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @run testng/othervm --add-opens jdk.incubator.vector/jdk.incubator.vector=ALL-UNNAMED
* -XX:-TieredCompilation ShortMaxVectorLoadStoreTests
*
@ -47,12 +47,11 @@ import java.nio.ByteBuffer;
import java.nio.ShortBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class ShortMaxVectorLoadStoreTests extends AbstractVectorTest {
public class ShortMaxVectorLoadStoreTests extends AbstractVectorLoadStoreTest {
static final VectorSpecies<Short> SPECIES =
ShortVector.SPECIES_MAX;

@ -23,7 +23,7 @@
/*
* @test
* @modules jdk.incubator.vector java.base/jdk.internal.vm.annotation
* @modules jdk.incubator.foreign jdk.incubator.vector java.base/jdk.internal.vm.annotation
#if[MaxBit]
* @run testng/othervm --add-opens jdk.incubator.vector/jdk.incubator.vector=ALL-UNNAMED
* -XX:-TieredCompilation $vectorteststype$
@ -57,12 +57,11 @@ import java.nio.$Type$Buffer;
#end[!byte]
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
@Test
public class $vectorteststype$ extends AbstractVectorTest {
public class $vectorteststype$ extends AbstractVectorLoadStoreTest {
#if[MaxBit]
static final VectorSpecies<$Wideboxtype$> SPECIES =
$Type$Vector.SPECIES_MAX;

@ -0,0 +1,50 @@
/*
* Copyright (c) 2021, 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 8254571
* @summary Erroneous generic type inference in a lambda expression with a checked exception
* @compile ConsiderExceptionTVarsInStuckExprs.java
*/
class ConsiderExceptionTVarsInStuckExprs {
public static void test() {
outer(nested(x -> mightThrow()));
outer(nested(ConsiderExceptionTVarsInStuckExprs::mightThrow2));
}
static <A> void outer(Object o) {}
static <B, C, E extends Throwable> B nested(Fun<C,E> fun) {
return null;
}
interface Fun<X, Y extends Throwable> {
void m(X t) throws Y;
}
static void mightThrow() throws Exception {}
static <C> void mightThrow2(C c) throws Exception {}
}

@ -42,6 +42,20 @@ public class DisambiguateParenthesizedPattern {
ExpressionType.EXPRESSION);
test.disambiguationTest("((0x1))",
ExpressionType.EXPRESSION);
test.disambiguationTest("(a > b)",
ExpressionType.EXPRESSION);
test.disambiguationTest("(a >> b)",
ExpressionType.EXPRESSION);
test.disambiguationTest("(a >>> b)",
ExpressionType.EXPRESSION);
test.disambiguationTest("(a < b | a > b)",
ExpressionType.EXPRESSION);
test.disambiguationTest("(a << b | a >> b)",
ExpressionType.EXPRESSION);
test.disambiguationTest("(a << b || a < b | a >>> b)",
ExpressionType.EXPRESSION);
test.disambiguationTest("(a < c.d > b)",
ExpressionType.PATTERN);
}
private final ParserFactory factory;

@ -23,7 +23,7 @@
/**
* @test
* @bug 8262891
* @bug 8262891 8268871
* @summary Check exhaustiveness of switches over sealed types.
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
@ -369,49 +369,6 @@ public class Exhaustiveness extends TestRunner {
""");
}
private void doTest(Path base, String[] libraryCode, String testCode, String... expectedErrors) throws IOException {
Path current = base.resolve(".");
Path libSrc = current.resolve("lib-src");
for (String code : libraryCode) {
tb.writeJavaFiles(libSrc, code);
}
Path libClasses = current.resolve("libClasses");
Files.createDirectories(libClasses);
new JavacTask(tb)
.options("--enable-preview",
"-source", JAVA_VERSION)
.outdir(libClasses)
.files(tb.findJavaFiles(libSrc))
.run();
Path src = current.resolve("src");
tb.writeJavaFiles(src, testCode);
Path classes = current.resolve("libClasses");
Files.createDirectories(libClasses);
var log =
new JavacTask(tb)
.options("--enable-preview",
"-source", JAVA_VERSION,
"-XDrawDiagnostics",
"-Xlint:-preview",
"--class-path", libClasses.toString())
.outdir(classes)
.files(tb.findJavaFiles(src))
.run(expectedErrors.length > 0 ? Task.Expect.FAIL : Task.Expect.SUCCESS)
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);
if (expectedErrors.length > 0 && !List.of(expectedErrors).equals(log)) {
throw new AssertionError("Incorrect errors, expected: " + List.of(expectedErrors) +
", actual: " + log);
}
}
@Test
public void testInaccessiblePermitted(Path base) throws IOException {
Path current = base.resolve(".");
@ -640,4 +597,225 @@ public class Exhaustiveness extends TestRunner {
""");
}
@Test
public void testExhaustiveTransitive(Path base) throws Exception {
doTest(base,
new String[]{"""
package lib;
public sealed interface S permits A, B {}
""",
"""
package lib;
public final class A implements S {}
""",
"""
package lib;
public abstract sealed class B implements S permits C, D {}
""",
"""
package lib;
public final class C extends B {}
""",
"""
package lib;
public final class D extends B {}
"""},
"""
package test;
import lib.*;
public class Test {
private int test(S obj, boolean b) {
return switch (obj) {
case A a -> 0;
case C c && b -> 0;
case C c -> 0;
case D d -> 0;
};
}
}
""");
}
@Test
public void testNotExhaustiveTransitive(Path base) throws Exception {
doTest(base,
new String[]{"""
package lib;
public sealed interface S permits A, B {}
""",
"""
package lib;
public final class A implements S {}
""",
"""
package lib;
public abstract sealed class B implements S permits C, D {}
""",
"""
package lib;
public final class C extends B {}
""",
"""
package lib;
public final class D extends B {}
"""},
"""
package test;
import lib.*;
public class Test {
private int test(S obj, boolean b) {
return switch (obj) {
case A a -> 0;
case C c -> 0;
case D d && b -> 0;
};
}
}
""",
"Test.java:5:16: compiler.err.not.exhaustive",
"- compiler.note.preview.filename: Test.java, DEFAULT",
"- compiler.note.preview.recompile",
"1 error");
}
@Test
public void testExhaustiveIntersection(Path base) throws Exception {
doTest(base,
new String[]{"""
package lib;
public sealed interface S permits A, B {}
""",
"""
package lib;
public abstract class Base {}
""",
"""
package lib;
public interface Marker {}
""",
"""
package lib;
public final class A extends Base implements S, Marker {}
""",
"""
package lib;
public abstract sealed class B extends Base implements S permits C, D {}
""",
"""
package lib;
public final class C extends B implements Marker {}
""",
"""
package lib;
public final class D extends B implements Marker {}
"""},
"""
package test;
import lib.*;
public class Test {
private <T extends Base & S & Marker> int test(T obj, boolean b) {
return switch (obj) {
case A a -> 0;
case C c && b -> 0;
case C c -> 0;
case D d -> 0;
};
}
}
""");
}
@Test
public void testNotExhaustiveIntersection(Path base) throws Exception {
doTest(base,
new String[]{"""
package lib;
public sealed interface S permits A, B {}
""",
"""
package lib;
public abstract class Base {}
""",
"""
package lib;
public interface Marker {}
""",
"""
package lib;
public final class A extends Base implements S, Marker {}
""",
"""
package lib;
public abstract sealed class B extends Base implements S permits C, D {}
""",
"""
package lib;
public final class C extends B implements Marker {}
""",
"""
package lib;
public final class D extends B implements Marker {}
"""},
"""
package test;
import lib.*;
public class Test {
private <T extends Base & S & Marker> int test(T obj, boolean b) {
return switch (obj) {
case A a -> 0;
case C c -> 0;
case D d && b -> 0;
};
}
}
""",
"Test.java:5:16: compiler.err.not.exhaustive",
"- compiler.note.preview.filename: Test.java, DEFAULT",
"- compiler.note.preview.recompile",
"1 error");
}
private void doTest(Path base, String[] libraryCode, String testCode, String... expectedErrors) throws IOException {
Path current = base.resolve(".");
Path libSrc = current.resolve("lib-src");
for (String code : libraryCode) {
tb.writeJavaFiles(libSrc, code);
}
Path libClasses = current.resolve("libClasses");
Files.createDirectories(libClasses);
new JavacTask(tb)
.options("--enable-preview",
"-source", JAVA_VERSION)
.outdir(libClasses)
.files(tb.findJavaFiles(libSrc))
.run();
Path src = current.resolve("src");
tb.writeJavaFiles(src, testCode);
Path classes = current.resolve("libClasses");
Files.createDirectories(libClasses);
var log =
new JavacTask(tb)
.options("--enable-preview",
"-source", JAVA_VERSION,
"-XDrawDiagnostics",
"-Xlint:-preview",
"--class-path", libClasses.toString())
.outdir(classes)
.files(tb.findJavaFiles(src))
.run(expectedErrors.length > 0 ? Task.Expect.FAIL : Task.Expect.SUCCESS)
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);
if (expectedErrors.length > 0 && !List.of(expectedErrors).equals(log)) {
throw new AssertionError("Incorrect errors, expected: " + List.of(expectedErrors) +
", actual: " + log);
}
}
}

@ -46,6 +46,9 @@ public class Guards {
runIfTrue(this::typeGuardIfTrueIfStatement);
runIfTrue(this::typeGuardIfTrueSwitchExpression);
runIfTrue(this::typeGuardIfTrueSwitchStatement);
runIfTrue(this::typeGuardAfterParenthesizedTrueSwitchStatement);
runIfTrue(this::typeGuardAfterParenthesizedTrueSwitchExpression);
runIfTrue(this::typeGuardAfterParenthesizedTrueIfStatement);
}
void run(Function<Object, String> convert) {
@ -122,6 +125,32 @@ public class Guards {
}
}
String typeGuardAfterParenthesizedTrueSwitchStatement(Object o) {
switch (o) {
case (Integer i) && i == 0: o = String.valueOf(i); return "true";
case ((Integer i) && i == 2): o = String.valueOf(i); return "second";
case Object x: return "any";
}
}
String typeGuardAfterParenthesizedTrueSwitchExpression(Object o) {
return switch (o) {
case (Integer i) && i == 0: o = String.valueOf(i); yield "true";
case ((Integer i) && i == 2): o = String.valueOf(i); yield "second";
case Object x: yield "any";
};
}
String typeGuardAfterParenthesizedTrueIfStatement(Object o) {
if (o != null && o instanceof ((Integer i) && i == 0)) {
return "true";
} else if (o != null && o instanceof (((Integer i) && i == 2)) && (o = i) != null) {
return "second";
} else {
return "any";
}
}
String testPatternInGuard(Object o) {
if (o instanceof (CharSequence cs && cs instanceof String s)) {
return s;

@ -0,0 +1,72 @@
/*
* Copyright (c) 2021, 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 8267610
* @summary LambdaToMethod cannot capture pattern variables. So the TransPatterns should
* transform the pattern variables and symbols to normal variables and symbols.
* @compile --enable-preview -source ${jdk.version} LambdaCannotCapturePatternVariables.java
* @run main/othervm --enable-preview LambdaCannotCapturePatternVariables
*/
import java.util.function.Supplier;
public class LambdaCannotCapturePatternVariables {
public static void main(String[] args) {
var testVar = new LambdaCannotCapturePatternVariables();
testVar.testInstanceOfPatternVariable(Integer.valueOf(1));
testVar.testSwitchPatternVariable(Integer.valueOf(1));
testVar.test(Integer.valueOf(1));
}
public Integer testInstanceOfPatternVariable(Object x) {
if(x instanceof Number y) {
return ((Supplier<Integer>) (() -> {
return ((y instanceof Integer z) ? z : 1);
})).get();
}
return null;
}
public Integer testSwitchPatternVariable(Object x) {
switch (x) {
case Number n: {
return ((Supplier<Integer>) (() -> {
return ((n instanceof Integer i) ? i : 1);
})).get();
}
default: return null;
}
}
// Provided by the user
public Integer test(Object x) {
Integer bar = 1;
return ((x instanceof Number y) ?
((Supplier<Integer>) (() -> {
return ((y instanceof Integer z) ? z : bar);
})).get() : bar);
}
}

@ -0,0 +1,114 @@
/*
* Copyright (c) 2021, 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 8268748
* @summary Javac generates error opcodes when using nest pattern variables
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
* jdk.jdeps/com.sun.tools.classfile
* @build toolbox.ToolBox toolbox.JavacTask
* @run main NestedPatternVariablesBytecode
*/
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.stream.StreamSupport;
import com.sun.tools.classfile.ClassFile;
import com.sun.tools.classfile.ConstantPoolException;
import com.sun.tools.classfile.Method;
import com.sun.tools.classfile.Attribute;
import com.sun.tools.classfile.Code_attribute;
import com.sun.tools.classfile.Instruction;
import toolbox.JavacTask;
import toolbox.TestRunner;
import toolbox.ToolBox;
public class NestedPatternVariablesBytecode extends TestRunner {
private static final String JAVA_VERSION = System.getProperty("java.specification.version");
private static final String TEST_METHOD = "test";
ToolBox tb;
ClassFile cf;
public NestedPatternVariablesBytecode() {
super(System.err);
tb = new ToolBox();
}
public static void main(String[] args) throws Exception {
NestedPatternVariablesBytecode t = new NestedPatternVariablesBytecode();
t.runTests();
}
@Test
public void testNestedPatternVariablesBytecode() throws Exception {
String code = """
class NestedPatterVariablesTest {
String test(Object o) {
if (o instanceof (CharSequence cs && cs instanceof String s)) {
return s;
}
return null;
}
}""";
Path curPath = Path.of(".");
new JavacTask(tb)
.options("--enable-preview", "-source", JAVA_VERSION)
.sources(code)
.outdir(curPath)
.run();
cf = ClassFile.read(curPath.resolve("NestedPatterVariablesTest.class"));
Method testMethod = Arrays.stream(cf.methods)
.filter(m -> isTestMethod(m))
.findAny()
.get();
Code_attribute code_attribute = (Code_attribute) testMethod.attributes.get(Attribute.Code);
List<String> actualCode = getCodeInstructions(code_attribute);
List<String> expectedCode = Arrays.asList(
"aload_1", "instanceof", "ifeq", "aload_1", "checkcast", "astore_2", "aload_2", "instanceof",
"ifeq", "aload_2", "checkcast", "astore_3", "aload_3", "areturn", "aconst_null", "areturn");
tb.checkEqual(expectedCode, actualCode);
}
boolean isTestMethod(Method m) {
try {
return TEST_METHOD.equals(m.getName(cf.constant_pool));
} catch (ConstantPoolException e) {
throw new IllegalStateException(e);
}
}
List<String> getCodeInstructions(Code_attribute code) {
return StreamSupport.stream(code.getInstructions().spliterator(), false)
.map(Instruction::getMnemonic)
.toList();
}
}

@ -2,10 +2,24 @@
* @test /nodynamiccopyright/
* @bug 8263590
* @summary Verify correct warnings are produced for raw types in bindings
* @compile/ref=RawTypeBindingWarning.out -Xlint:rawtypes -XDrawDiagnostics RawTypeBindingWarning.java
* @compile/ref=RawTypeBindingWarning.out -Xlint:rawtypes -XDrawDiagnostics --enable-preview -source ${jdk.version} RawTypeBindingWarning.java
*/
public class RawTypeBindingWarning<T> {
public static boolean t(Object o) {
return o instanceof RawTypeBindingWarning w;
}
public static void t2(Object o) {
switch (o) {
case RawTypeBindingWarning w -> {}
default -> {}
}
switch (o) {
case (RawTypeBindingWarning w) -> {}
default -> {}
}
switch (o) {
case (RawTypeBindingWarning w && false) -> {}
default -> {}
}
}
}

@ -1,2 +1,7 @@
RawTypeBindingWarning.java:9:29: compiler.warn.raw.class.use: RawTypeBindingWarning, RawTypeBindingWarning<T>
1 warning
RawTypeBindingWarning.java:13:18: compiler.warn.raw.class.use: RawTypeBindingWarning, RawTypeBindingWarning<T>
RawTypeBindingWarning.java:17:19: compiler.warn.raw.class.use: RawTypeBindingWarning, RawTypeBindingWarning<T>
RawTypeBindingWarning.java:21:19: compiler.warn.raw.class.use: RawTypeBindingWarning, RawTypeBindingWarning<T>
- compiler.note.preview.filename: RawTypeBindingWarning.java, DEFAULT
- compiler.note.preview.recompile
4 warnings

@ -0,0 +1,157 @@
/*
* Copyright (c) 2021, 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 8268896
* @summary Verify source level checks are performed properly
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
* jdk.compiler/com.sun.tools.javac.util
* @build toolbox.ToolBox toolbox.JavacTask
* @run main SourceLevelChecks
*/
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import toolbox.TestRunner;
import toolbox.JavacTask;
import toolbox.Task;
import toolbox.ToolBox;
public class SourceLevelChecks extends TestRunner {
private static final String JAVA_VERSION = System.getProperty("java.specification.version");
ToolBox tb;
public static void main(String... args) throws Exception {
new SourceLevelChecks().runTests();
}
SourceLevelChecks() {
super(System.err);
tb = new ToolBox();
}
public void runTests() throws Exception {
runTests(m -> new Object[] { Paths.get(m.getName()) });
}
@Test
public void testPattern(Path base) throws Exception {
doTest(base,
"""
package test;
public class Test {
private void test(Integer i) {
switch (i) {
case Integer d:
}
}
}
""",
"Test.java:5:26: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.pattern.switch)",
"1 error");
}
@Test
public void testParenthesizedPatternIf(Path base) throws Exception {
doTest(base,
"""
package test;
public class Test {
private void test(Object o) {
if (o instanceof (Integer d)) {
}
}
}
""",
"Test.java:4:26: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.pattern.switch)",
"1 error");
}
@Test
public void testParenthesizedPatternSwitch(Path base) throws Exception {
doTest(base,
"""
package test;
public class Test {
private void test(Integer i) {
switch (i) {
case (Integer d):
}
}
}
""",
"Test.java:5:18: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.pattern.switch)",
"1 error");
}
@Test
public void testCaseDefault(Path base) throws Exception {
doTest(base,
"""
package test;
public class Test {
private void test(Integer i) {
switch (i) {
case default:
}
}
}
""",
"Test.java:5:18: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.pattern.switch)",
"1 error");
}
private void doTest(Path base, String testCode, String... expectedErrors) throws IOException {
Path current = base.resolve(".");
Path src = current.resolve("src");
Path classes = current.resolve("classes");
tb.writeJavaFiles(src, testCode);
Files.createDirectories(classes);
var log =
new JavacTask(tb)
.options("-source", "11",
"-Xlint:-options",
"-XDrawDiagnostics")
.outdir(classes)
.files(tb.findJavaFiles(src))
.run(Task.Expect.FAIL)
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);
if (!List.of(expectedErrors).equals(log)) {
throw new AssertionError("Incorrect errors, expected: " + List.of(expectedErrors) +
", actual: " + log);
}
}
}